Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > mySQL & PHP

Notices

mySQL & PHP Discussions, information and help with mySQL and PHP.

Reply
 
LinkBack Thread Tools
  #1  
Old 01-14-2008, 04:05 AM
Phoubers's Avatar
Sergeant
 
Join Date: Oct 2007
Location: :D
Posts: 34
Default Php Problem

Hello,
I am having a php problem and I looked all over the internet and different search engines for the answer... I have already posted this a long time ago but now it is edited.
Note: My connection to the database is stable
__________________________________________________ ___________
$query = ("INSERT INTO users (firstname, lastname, username, password, email, date, rank, status, key) VALUES('$first', '$last', '$username', '$password', '$email', '$date', '$rank', '$status', '$key')");
if (!mysql_query($query, $con)) {
die('ERROR: ' . mysql_error());
}
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻ
I have rewritten an old code and seem to be having a problem writing data to my database. I receive this error

ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key) VALUES ('Matt', 'Pomeranz', 'Phoubers', 'password' at line 1
__________________
No its not Fowbers its foobers :D
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 01-14-2008, 06:23 AM
Watdaflip's Avatar
Brigadier General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 1,640
Default Re: Php Problem

First of all you should change your error handling. You need to close the database connection, so you should either make it
PHP Code:
 if (!mysql_query($query$con)) {
mysql_close($con);
  die(
'ERROR: ' mysql_error());
 } 
of just echo an error message and set a flag if needed...


Anyway, on to the error.

You need to change the name of the column "key" to something else, the word "key" is a reserved word in both php and mysql. Its fine to use it as a variable name (ie. $key is fine), but you can't use it as a column name in a database table. Once you change that the query should work fine.



PS. In your variables, you don't have to surround them with ().

For instance you have $query = ("");

You can just format it like $query = "";

Its not wrong, it still works, its just more work for you to type it, and for anyone else reading through your code it can make it less readable (depending on what else is being done). Just FYI.
__________________

Register/Login Script
Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 01-14-2008, 07:50 AM
Phoubers's Avatar
Sergeant
 
Join Date: Oct 2007
Location: :D
Posts: 34
Smile Re: Php Problem

After all the time I spent trying to figure it out..it was the word key. Thanks so much watdaflip your a genius. And those hints you gave me, Ill get on that right away.

Thank you
__________________
No its not Fowbers its foobers :D
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 01:07 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC7
2007 VodaHost.com - All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55