Page 1 of 1

php mysql database

Posted: Fri Jul 01, 2011 8:54 pm
by Alidad
hi, I'm trying to create registration forms, i wrote code and then run to test to make sure everything works fine but i'm getting errors that i can't figure out what did i missed to fix it.

the error said "Account CreatedYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''users' , `status` , `first_question` , `first_answer` , `second_question` , `se' at line 1"

and my insert code is

$qry="INSERT INTO `tbld_all_register` ( `first_name` , `last_name` , `country` , `city` , `state` , `zipcode` , `username` , `email` , `password` , `birthday` , `birthmonth` , `birthyear` , `gender` ,'users' , `status` , `first_question` , `first_answer` , `second_question` , `second_answer` )VALUES ( '$first_name', '$last_name', '$country', '$city', '$state', '$zip_code', '$usrnam', '$email', '$member_password', '$b_day', '$b_month', '$b_year', '$gender', '".$_POST['username']."', '1' , '$email', '".$_POST['first_question']."' , '".$_POST['first_answer']."' , '".$_POST['second_question']."' , '".$_POST['second_answer']."')";


and the database list is
first_name , last_name , country, city, state, zipcode, username, email, password, birthday, birthmonth, birthyear, gender, users, status, first_question, first answer, second_question, second_ answer

i can't hardly figure out went wrong, please help thanks.

AM

Re: php mysql database

Posted: Fri Jul 01, 2011 9:42 pm
by twinedev
First step in debugging a "You have an error in your SQL" if you cannot figure it out from the error message itself is to output the actual SQL statement you are trying to run (ie, in this case, echo $qry;). Many times things will stand out like a sore thumb when you look at the actual query instead of looking at the code that creates the query.

If that doesn't help, try copy and pasting the query directly to mySQL, sometimes you can get a more defined error to help ya.

But back to your code that you posted, you have 'users' wrapped with single quotes instead of backticks (`users`) to surround database/table/field names.

-Greg

Re: php mysql database

Posted: Fri Jul 01, 2011 10:28 pm
by Alidad
yes your right, show stupid i am that did not get enough attention on that code.
thanks so much for your help i mean that.

AM

Re: php mysql database

Posted: Sat Jul 02, 2011 2:24 am
by twinedev
NP, sometimes we stare at the code for so long, the simple things blur enough we don't see them wrong ;-)