PHP Code to subscribe email address

Prepared statements for update in PHP

Data from submitted for can be updated into MySql database through different ways,mean through Mysql queries as well as using prepared statements. In corporate environment prepared statements are used for fetching , interesting and updating data to Mysql database because these statements are a secure way. Security level increases if we use prepared statement. Here is code of prepared statement that inserts data to mysql table

$stmt = $conn->prepare(“UPDATE `table_name` SET col1=?, col2=? WHERE id=$id “); 

 $stmt->bind_param(“ss”,$col1, $col2);

 if ($stmt->execute()) { 
else { 
 $_SESSION[‘responseMsg’]=”There was an error saving data Please try again later” ;

 echo $_SESSION[‘responseMsg’];


In prepared statements columns are mapped. in first row we have two columns col1,col2 then we will have to use three question  (?) marks for mapping as well we will have to bind these columns in bind_param where we have used ‘ss’ because we know that two are strings so we used ss. Lastly we have executed prepared statements that returns success or failure result.

Leave a Reply

Your email address will not be published. Required fields are marked *