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/Zinin2018 Oct 13 '19

Whats the difference betn using query or exec?

2

u/greg8872 Oct 13 '19

assuming this is for plain PDO, query() returns a PDO Statement Object (which you can loop through and process the records returned), where exec() just runs the query and returns how many rows were affected. So if you doing a query that does not return records and you are not using any data that needs protected (submitted by user), use exec()