Home > database >  How can I use PDO with Prepared Statements for update SQL?
How can I use PDO with Prepared Statements for update SQL?

Time:12-26

Here is my SQL code to update the command but the code isn't working:

$bangla_update = $_POST['bangla_update'];
$english_update = $_POST['english_update'];
$example_update = $_POST['example_update'];
$synonym_update = $_POST['synonym_update'];
$mainid = $_GET['id'];
$stmt = $conn->prepare("UPDATE wordmeanings_table SET bangla=?, english=?, example=?, synonymwords=? WHERE id=?");
$stmt->bind_param("ssssi",$bangla_meaning,$english_meaning,$example_meaning,$synonym_meaning,$mainid);
$stmt->execute();
$stmt->close();

CodePudding user response:

Use execute rather than bind_param and set your args in an array

$english_update = $_POST['english_update'];
$example_update = $_POST['example_update'];
$synonym_update = $_POST['synonym_update'];
$mainid = $_GET['id'];

$stmt = $conn->prepare("UPDATE wordmeanings_table SET bangla=?, english=?, example=?, synonymwords=? WHERE id=?");

$stmt->execute([$bangla_meaning,$english_update,$example_update,$synonym_update,$mainid]);    
$stmt->close();
  • Related