POD Prepared Statement Error


#1

Hi,

My prepared statement for update is outputting ​ before the echo statement.

Here is my code

<?php

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
	mysql_set_charset('utf8',$db);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // prepare sql and bind parameters
    $stmt = $conn->prepare("UPDATE test SET name=:name WHERE scode=:scode");
    $stmt->bindParam(':name', $name);  
    $stmt->bindParam(':scode', $scode);

    // Update a row
    $name = $_POST['name'];
	$scode = $_POST['scode'];
    $stmt->execute();
	
 //Print the received data:
  print "Name updated to <br/>
		  <stronge>$name</stronge>" ; 	
	
}	
catch(PDOException $e) {
	
    echo "Error: " . $e->getMessage();
}
$conn = null;
 ?>

Here is the output

​ Name updated to
My Name

Can someone help me determine why this is happening? I am new to PHP so sorry if this is a simple fix. I am been working on it for a day and nothing I do seems to fix the issue.

Thanks in advance for your help.


#2

Is there some reason you are throwing obsolete mysql code in the middle of PDO Code? Perhaps you should take a minute and study this tutorial https://phpdelusions.net/pdo