This is a pretty dumb question. But I'm stucked. I use this statement to add a new record to the dababase: { $query = 'INSERT INTO w_table (maker, series, model, part) VALUE ($maker, $series, $model, $part); mysql_query($query); echo mysql_error(); } $maker, $series, $model and $part are retrieved from a file. Mysql_error () always complain that "Unknown column $maker in the fieldlist". The only to stop this error is to use the acutal values intead of variables inside the VALUE clause. What did I do wrong?
I figured it out. The variabble names need to be bwteen quotes. So that right way is VALUES ('$maker', '$series', '$model', ...) instead of VALUES ($maker, $series, $model, ...) I don't know why we need the qutation marks from parsing view point. But I don't want to argue with success. Warren
The reason you need them is so the database interprets the data you are inserting as a string. Something like inserting a number into an INT field, or using a MySQL function like DATE() would work without them, but MySQL doesn't know to handle the data as a string unless you tell it to.
I think you have prob with datatype... for string you should use single quotations and for int you can write values without quotations
I am not sure if the problem is solved or not, but correct way of writing the query would be.. $query = "INSERT INTO w_table (maker, series, model, part) VALUE ('$maker', '$series', '$model', '$part')";
$query = "INSERT INTO w_table (maker, series, model, part) VALUE ($maker, $series, $model, $part)"; should be VALUES and need the qutation marks '$maker', '$series', '$model', '$part' >> $query = "INSERT INTO w_table (maker, series, model, part) VALUES ('$maker', '$series', '$model', '$part')"; CMIIW