php mysql database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Alidad
Forum Commoner
Posts: 29
Joined: Thu Mar 29, 2007 12:42 pm

php mysql database

Post 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
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: php mysql database

Post 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
Alidad
Forum Commoner
Posts: 29
Joined: Thu Mar 29, 2007 12:42 pm

Re: php mysql database

Post 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
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: php mysql database

Post by twinedev »

NP, sometimes we stare at the code for so long, the simple things blur enough we don't see them wrong ;-)
Post Reply