.


Divya

PHP MySQLi Insert statement Example


index.php

<!DOCTYPE html>
<html>
<body>
<form method="POST" action="process.php">
First name:<br>
<input type="text" name="First_name">
<br>
Last name:<br>
<input type="text" name="Last_name">
<br>
City name:<br>
<input type="text" name="City_name">
<br>
Email Id:<br>
<input type="email" name="Email">
<br><br>
<input type="submit" name="save" value="submit">
</form>
</body>
</html>

process.php

<?php
$servername='localhost';
$username='root';
$password='';
$dbname = "my_db";
$conn=mysqli_connect($servername,$username,$password,"$dbname");
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$city_name = $_POST['city_name'];
$email = $_POST['email'];
// sql query for inserting data into database
mysqli_query($conn,"insert into students(first_name,last_name,city_name,email) values ('$first_name','$last_name','$city_name','$email')") or die(mysqli_error());
echo "Data addes successfully !";
?>


.