PHP – Insert Data Into MySQL Using Parameters

After a Database and a Table have been created, we can start adding data in them.

//Insertions method store in function for get / post

if(isset($_GET[‘memberpost’]))
{
session_start();
include(‘function/db.php’);
global $conn;

$sl1 = $_GET[‘l1’];
$sl2 = $_GET[‘l2’];
$sl3 = $_GET[‘l3’];
$sl4 = $_GET[‘l4’];
$sl15 = $_SESSION[‘session’];

date_default_timezone_set(“Asia/Kolkata”);
$sl6 = date(‘Y-m-d’);

$stmt = $conn->prepare(“INSERT INTO tab(l1, l2, l3, l4, l5, l6) VALUES (?,?,?,?,?,?)”);
$stmt->bind_param(“ssssss”,$l1,$l2,$l3,$l4,$l5,$l6);

//set parameters and execute
$l1 = $sl1;
$l2 = $sl2;
$l3 = $sl3;
$l4 = $sl4;
$l5 = $sl5;
$l6 = $sl6;
$stmt->execute();

$last_id = $conn->insert_id;
//echo “$l1    ,    $l2    ,    $l3    ,    $l4    ,    $l5    ,    $l6 “;
if($stmt)
{ echo “Successfully Post with id = $last_id”; }
else
{ echo “Error Ocure”; }
}

Published by Sushant Sharma

Technologist. Software Developer. Tech Analyst ।।।

One thought on “PHP – Insert Data Into MySQL Using Parameters

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started