how to insert data in the database using php and mysqli

Hello guys, Today we are learning MYSQLI INSERT QUERY execute in the database using php with mysqli. Then lets start.

Originally published at https://wikispaces.in - 14 Mar 2019 04:45 pm

1. HTML Source Code(Index.php)



<form action="send.php" method="post">

<input type="text" name="name" palceholder="Enter name">

<input type="submit" name="submit" value="Submit">

</form>



2. PHP Source Code(send.php)



<?php

$conn=mysqli_connect("localhost", "root", "", "testproject");

$name=$_POST["name"];

$query=mysqli_query($conn, "INSERT INTO userdetails(name) VALUES('$name')");

if(query==true){

echo"Successfully Inserted";

}

else{

echo"Inserted Failed";

}

?>