I UPDATE a single mysql record using a foreach loop which obtains the name and value of $_POST variable and UPDATES the record column at the time, the names of the $_POST variables are the same as the mysql column names
Here is the code
foreach ($_POST as $key => $value) {
$value = mysqli_real_escape_string($con, $value );
$value = strip_tags($value);
$sql="UPDATE properties SET $key = '$value' WHERE propertyID='$propertyID'";
$query = mysqli_query($con, $sql);
if (mysqli_errno($con)){$error=1;}
}//end foreach loop
unset($value);
unset($key);
This works fine
However I'm trying to convert the loop to use PDO. I have tried looking at previous posts on this subject but am still unable to make it work
Here is the code I have tried:
foreach ($_POST as $key => $value) {
$value = mysqli_real_escape_string($con, $value );
$value = strip_tags($value);
$sql="UPDATE vendors SET $key = '$value' WHERE vendorID='$vendorID'";
$stmt = $pdo->prepare($sql);
$stmt->bindValue($key, $value); //have also tried bindParam!!
$stmt->execute();
}//end foreach loop
unset($value);
unset($key);
This runs but doesn't update any of the columns, can anybody help please?
Thanx
Bob