r/PHPhelp • • Oct 13 '19

INSERT INTO sql table not working.

Am I inserting rows into my table correctly? This doesn't work for some reason.

$conn->exec("INSERT INTO Questions_Table (ID, Question, Votes) VALUES ($num_rows, $submitted_question, 1)");
9 Upvotes

9 comments sorted by

View all comments

2

u/PopeInnocentXIV Oct 13 '19

Are $num_rows and $submitted_question properly quoted and escaped?

1

u/[deleted] Oct 13 '19

$num_rows is an int and $submitted_question is a string, so I think they would be properly quoted

4

u/greg8872 Oct 13 '19

so if you do echo $submitted_question;

does it give back some value or does it give back "some value"?

To be honest, if it is something submitted, just use prepared statements to protect you for bad values being directly places in the query.

If I submitted a question that said (assuming you fix your quote issue) what color is the sky?",9999),(100,"Another Question? I may have now just submitted a two questions, and the first one I set the Votes to 999 for it.

1

u/PopeInnocentXIV Oct 13 '19

Echo out the statement and see if it looks correct.

Also get the error message from the database connection.