Wednesday, 28 February 2018

Data Base Connectivity By using PHP

<?php
$con = mysqli_connect("localhost","root","","Assignment");
if (mysqli_connect_error()) // if not connected
{
  echo "Cannot connect to database";
}
else
{
$first=$_POST["fname"];
$last=$_POST["lname"];

$subj=$_POST["subject"];
$gender=$_POST["gender"];

$lang=$_POST["lang"];
$q=mysqli_query($con,"INSERT INTO student(Fname,Lname,Subject,Gender,language) VALUES('$first','$last','$subj','$gender','$lang')");
if(!$q)
{
echo "insertion failed....";
}
else
{
    ?>
     <script>
     var conf = confirm("successfully data inserted....");
   if(conf)
 
 window.location="index.html";
</script>
 <?php
mysqli_close($con);


}
}

?>