Monday, 24 June 2013

Database Connection


<html>
<head>
<title> Student Database</title>
</head>
<body>

<form action="index.php" method="post">
Enter student ID
<input type="text" id="num" name="s_id">
<input type="submit" id="sub" value="submit">
</form>
<?php
    $con=mysqli_connect("
localhost","root","","student");
// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
else
   echo "connected to database<br><br>";
    $x=$_POST['s_id'];
//echo "nummmmmm".$x."<br>";
 $res=mysqli_query($con, "SELECT * FROM STUDENT_DETAILS WHERE id='$x'");
 if($res='')
         echo "No such id! Try Again!!";


while($row = mysqli_fetch_array($res))
  {
  echo "<bt />";
  echo $row['id'] . " " . $row['name']." ".$row['marks'];
  echo "<br>Percentage=".$row['marks']*100/40;
  echo "<br />";
  }

mysqli_close($con);
?>

</body>
</html>

No comments:

Post a Comment