tags:

views:

62

answers:

3

Ok I have been using PHP + MySQL for a while so I consider myself proficient. I have made my fair share of syntactical mistakes in the past but this is honestly pissing me off:

http://img251.imageshack.us/img251/3760/fubar.png

If anyone can tell me why this simple statement isn't working I would be greatly appreciative.

+6  A: 

Actually I do see 1 error..."Option" is a reserved word. wrap it in backtics : `Option` or better yet, change the column name to something that's not a reserved word.

Crayon Violent
Precisely the problem. Thank you.
Glenn Nelson
+2  A: 

Looking at the code you're trying to insert what comes from $_POST['survey'], so your insert should look like this:

$vote = $_POST['survey'];

// connect to db

mysql_query(sprintf(
    "INSERT INTO poll (`Option`) VALUES ('%s')", 
    mysql_real_escape_string($vote)
);

Also note that "option" is a reserved keyword and needs to be inside backticks.

halfdan
You forgot `sprintf` :)
Fanis
@Fanis: God, what a FAIL :-( Fixed it.
halfdan
+3  A: 

Use backticks for 'option'.

INSERT INTO poll (`Option`) VALUES ('Stuff')
vassilis
Or just do `INSERT INTO poll VALUES ('Stuff')`. There's no need to specify the column name.
Mark Snidovich
@Mark Snidovich - well that's only true if you plan on providing values for every column (and in the right column order). In general that isn't very good practice though, because if you decide to add another column to the table later on, for some other script...it's going to break this statement.
Crayon Violent
@Crayon that's true, but in this case, the table has only one column. That is how I do things, generally - provide a value for each column and if I change the table, I'd better be careful. Good points though, i guess it depends if you want resiliency or would rather to be forced to be precise in the values provided.
Mark Snidovich