PDA

View Full Version : is this a valid query?


Heywood
07-03-2003, 09:37 AM
I am stumped. Basically, I have an html form that uses a script to take those variables entered in the form, and put them into a table. This is extremely simple, and something I have done easily before, but this time, I am getting a weird error. Is this correct?

$sql = 'INSERT INTO main (id,name,url,suburl,recip) VALUES (\' $id \', \' $name \', \' $url \', \' $suburl \', \' $recip \')';


This should submit the variables from my form into the table. Instead it strores the variable name, as if it were a string.

here is what the entries in my table look like:

id name url suburl recip
1 $name $url $suburl $recip
2 $name $url $suburl $recip


Does anyone know what I am doing wrong here?

raf
07-03-2003, 11:03 AM
The problem is probably the id-column. I suppose it is a column of type 'autonom' (auto-generated value, for the primery key of that table). When inserting a record in a table with an autonum-column, you can not include a value for that column.
Or if it is a column of a numeric type (int, smallint etc), then the values can't be enclosed in quotes.
Also, it could be that there are quotes inside the values for the string - columns --> so use addslashes on the variabels
I'd also use double quotes. So it should probably be

$name=addslashes($name)
...
$sql="INSERT INTO main (name,url,suburl,recip) VALUES ('$name','$url','$suburl','$recip')";