Tuesday, July 9, 2019

PHP AND MYSQLI DATABASE



1.How we create database?


Create a database called save. In the save database, add a table called save_table. The users table will take the following four fields.





2.How we create Connection?

Create file with the name connect.php 
And past below code in that file.
<?php
$db=mysqli_connect('localhost','root','','Save');
if($db=true){
echo"Connect Succesfull";
}
else{
echo"Connection Failed";
}
?>




How we insert data in database by user?

create a file with name save.php 
and past the below code in it .

<?php
$db=mysqli_connect('localhost','root','','Save');
If(isset($_POST['save'])){
 $nm =$_POST['nm'];
 $fnm =$_POST['fnm'];
 if($nm == '' OR $fnm==''){
  echo"Field is reqired";
 }
 else{ 
  $que ="INSERT INTO save_table(User_Name,User_Father_Name) 
  VALUES('$nm','$fnm')";
  $run = mysqli_query($db,$que);
  if($run= true){
   echo" DATA registered Successfully";
  }
 }
}
?>
<html>
<head>
<title> User Registration </title>
</head>
<body>
<form method="post" action="save.php">
<center>
<table>
<tr>
<th>Name</th>
<td><input name="nm" type="text"></td>
</tr>
<tr>
<th>F.Name</th>
<td><input name="fnm" type="text"></td>
</tr>
<tr>
<td><input name="save" type="submit" value="save"></td>
</tr>
<center>
</table>
</form>
</body>
</html>




User Registration
Name
F.Name

No comments:

Post a Comment