Page 1 of 1

mysql INSERT command isn't working [solved]

Posted: Sun Mar 08, 2015 4:28 am
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...'

Re: mysql INSERT command isn't working.

Posted: Sun Mar 08, 2015 5:26 am
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.

Re: mysql INSERT command isn't working.

Posted: Sun Mar 08, 2015 6:00 pm
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.

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

Posted: Mon Mar 09, 2015 7:42 am
by jameshutchings
The problem seemed to be 'keyword 1' and 'keyword 2'. When I changed them to 'keyword1' and 'keyword2' it worked.

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

Posted: Tue Mar 10, 2015 4:04 am
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.