How to insert value into the database with the help of php?

When we know how to connect the PHP page into the database.so we are starting to know how to insert a value into the database from PHP.here is code————–

$sql="insert into product values('null','$productname','$quantity')"

$sql= It is a variable to store an inserting values.

product= It is a database table name.

null,$productname, and $quantity= It is a variable of HTML same as database table field name.

when we know how to insert a value in a database from PHP.so we write a PHP code how to insert a value.here is a code—-

$check=isset($_POST['check'])?TRUE:FALSE;
//$productno="";
$productname="";
$quantity="";
 if($check)
 //$productno=$_POST['productno'];
 {
 $productname=$_POST['productname'];
 $quantity=$_POST['quantity'];
 $connection=mysqli_connect("localhost", "root", "", "stockmanagemant");
 $sql="insert into product values('null','$productname','$quantity')";
 $sql=mysqli_query($connection,$sql);
 }

In this code, you can also familiar with a  $check and his uses.

 

Leave a Reply