mysql INSERT command isn't working [solved]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
jameshutchings
Posts: 8
Joined: Sun Mar 08, 2015 4:18 am

mysql INSERT command isn't working [solved]

Post by jameshutchings »

I'm trying to set up a system which registers accounts.

The page where you register is http://www.apolitical.info/private/teleleegame

The registration does what it's supposed to: put your email, password and a random code into a MySQL database called 'pending', and send you an email with a link.

The link goes to another page, which does *most* of what it's supposed to:

"roll up' your characters (works)
delete you from the 'pending' database (works)
put you into the 'current' database (works)

but it doesn't put your character's details into the 'characters' database properly.

Here's an example of the MySQL command which is supposed to do that:

Code: Select all

INSERT INTO characters (email,background,Stamina,Luck,Willpower,Perception,Technology,Magic,Combat,Stealth,Streetwise,Wilderness,Riding,Charisma,Healing,Shells,keyword 1,keyword 2,vice,toedit) VALUES ('news@apolitical.info','travelling merchant',8,5,1,0,0,-2,0,-2,-1,1,1,1,0,6,' ',' ','being virtuous when those around them were not',1)
(the page prints out the MySQL command so I can see what's going on- it's not supposed to do that in the finished version).

I've checked that the 'characters' database has the right types for all the columns eg 'email' is varchar(50) while 'Magic' is int(2).

But it still doesn't work.

PS Not sure if this is relevant, but I have it in the form

Code: Select all

$result=mysql_query($w1,$link)
: $w1 is a string equivalent to the above 'INSERT INTO...'
Last edited by jameshutchings on Mon Mar 09, 2015 7:41 am, edited 1 time in total.
User avatar
a_bertrand
Posts: 1537
Joined: Mon Feb 25, 2013 1:46 pm

Re: mysql INSERT command isn't working.

Post by a_bertrand »

Try to run your SQL statement directly (from phpmyadmin or the command line) and see if you get some error message. Quite likely you have a mistake in the statement and therefore your insert is not done.
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: mysql INSERT command isn't working.

Post by Jackolantern »

I would second that advice. You are inserting a ton of values up there, so it is likely there is a spelling error or other such error in there.
The indelible lord of tl;dr
jameshutchings
Posts: 8
Joined: Sun Mar 08, 2015 4:18 am

Re: mysql INSERT command isn't working [solved]

Post by jameshutchings »

The problem seemed to be 'keyword 1' and 'keyword 2'. When I changed them to 'keyword1' and 'keyword2' it worked.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: mysql INSERT command isn't working [solved]

Post by Jackolantern »

Ahh, I didn't even see that. You can have a space in a name in MySQL, but to use it that way in PHP, you must put back-ticks around it like:

Code: Select all

`keyword 1`
But it is generally not a good idea to give MySQL fields names that are not valid PHP identifiers. Later down the line if you wanted to switch to an ORM for data access, it could cause a lot of problems.

But if keyword1 worked, that must have been the name you gave it in the database.
The indelible lord of tl;dr
Post Reply

Return to “Beginner Help and Support”