PHP Code to subscribe email address

Prepared statements for insertion in PHP

Data from submitted for can be interested 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 and interesting data to MySQL database because these statements are a secure way. Security level increases if we use prepared statement. Here Here is code of prepared statement that inserts data to MySQL table

$stmt = $conn->prepare(“INSERT INTO table_name(id, col1,col2) VALUES (?,?, ?)”);

if ($stmt->execute()) {
} else {

$_SESSION[‘responseMsg’]=”There was an error saving data.Please try again later” ;

In prepared statements columns are mapped. in first row we have three columns id,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 ‘iss’ because we know that first column is integer and other tow are strings so we used is. 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 *