BastiaanWW BastiaanWW - 14 days ago 5
PHP Question

php PDO insert not working, no error

I have this peace of code that should insert a record into a mysql database:

$sql = "INSERT INTO connections (column1, column2, column3, column4, column5, column6, column7) VALUES (?, ?, ?, ?, ?, ?, ?)')";
$stmt = $pdo->prepare($sql);
if (!$stmt) {
echo "\nPDO::errorInfo():\n";
print_r($pdo->errorInfo());
}
$stmt->execute(array('wer','wer','wer','2','wer','wer','wer'));


I don't get any error and the record does not show up in the table. What could be going wrong?

UPDATE:

THis is the full working code thanks to the answer below:

$sql = "INSERT INTO connections (column1, column2, column3, column4, column5, column6, column7) VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
if (!$stmt) {
echo "\nPDO::errorInfo():\n";
print_r($pdo->errorInfo());
}
$stmt->execute(array('wer','wer','wer','2','wer','wer','wer'));

Answer

There is a syntax error at the end of the SQL command. Remove the extra '). It should be:

$sql = "INSERT INTO connections (column1, column2, column3, column4, column5, column6, column7) 
        VALUES (?, ?, ?, ?, ?, ?, ?)";

Instead of

$sql = "INSERT INTO connections (column1, column2, column3, column4, column5, column6, column7) 
        VALUES (?, ?, ?, ?, ?, ?, ?)')";
                                    ^^--- error here
Comments