PDA

View Full Version : SQL error, tried to figure it out, but not sure why it isn't working


kobescoresagain
04-01-2006, 12:37 AM
Okay here is the table layout
id int(8) No 0
name varchar(50) Yes NULL
dob varchar(50) Yes NULL
height varchar(50) Yes NULL
weight int(3) Yes 0
jersey varchar(50) Yes NULL
from varchar(50) Yes NULL
position varchar(50) Yes NULL
teamname varchar(50) Yes NULL
sport varchar(25) Yes NULL

Here is the mysql query
$query = "INSERT INTO add_temp_player (id, name, height, weight, jersey, from, position, teamname, sport) VALUES ($_POST[id2],'$_POST[name]','$_POST[height]',$_POST[weight],'$_POST[number]','$_POST[from]','$_POST[position]','$_POST[team]','$_POST[sport]')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

When I echo out the $query I get this
INSERT INTO add_temp_player (id, name, height, weight, jersey, from, position, teamname, sport) VALUES (59,'Larry Hughes',' 6-5',184,' 32',' St. Louis',' G','cavaliers','')

Here is the error
Query failed: 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 'from, position, teamname, sport) VALUES (591,'Luis Alicea','',0

The database is connected, because the other queries, on the same page work.

Which looks right to me. I am not sure why it isn't working, can anyone help me out.

Thanks

Xenon
04-01-2006, 09:27 AM
from, position, teamname,

you are using a mysql keyword within your query, which produces the error

i suggest to rename the field via phpmyadmin and change the query :)

Code Monkey
04-01-2006, 01:21 PM
Yeah, you can't use keywords.

On a side note, I notice some of the data has leading spaces. You might want to trim() your data before entry to remove leading and trailing spaces. They are usualy the result of copy/paste data entry into forms.

kobescoresagain
04-04-2006, 02:15 PM
Thanks, I will add that, I noticed that as well, just hadn't done it yet.