Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. 0) { $row = mysqli_fetch_assoc($results); echo "Grade : ".$row['Grade']; } else { echo "Error: ".$sql."
  2. ".mysqli_error($con); } mysqli_close($con); } ?>
  3.  
  4. <!DOCTYPE html>
  5. <html>
  6. <body>
  7. <script type="text/javascript">
  8. function checkFunc()
  9. {
  10. var indexNum = document.getElementById("indexBoxID").value;
  11. var nameBoxCheck = document.getElementById("nameBoxID").value;
  12. $bool=false;
  13. if(indexNum=="" && nameBoxCheck=="")
  14. {
  15. document.getElementById("nameBoxID").value="Can't be Empty";
  16. document.getElementById("indexBoxID").value="Can't be Empty";
  17. }
  18.  
  19. else
  20. {
  21. if(indexNum.slice(0,2)=="as")
  22. {
  23. document.getElementById("nameBoxID").innerHTML="Please Type Index letters in Capital form";
  24. }
  25.  
  26. else if(indexNum.slice(0,2)!="AS"&&indexNum.slice(0,2)!="as")
  27. {
  28. document.getElementById("indexBoxID").value="Not valid";
  29. }
  30. else
  31. $bool=true;
  32. //$.ajax({ url:'capture.php',type: 'post'}).done(function(){alert(JSON.stringify("Done"))});
  33.  
  34. }
  35. return $bool;
  36. }
  37. </script>
  38.  
  39. <form action="capture.php" method="POST" onsubmit="return checkFunc();">
  40. Name : <input type="text" id="nameBoxID" name="nameBox"><br>
  41. Index : <input type="text" id="indexBoxID" name="indexBox"><br>
  42. Grade : <input type="text" id="gradeBoxID" name="gradeBox" value="" readonly><br><br>
  43. <input type="submit" value="Submit">
  44.  
  45. </body>
  46. </html>
  47.  
  48. <?php
  49. $nameBoxPhp =$_POST["nameBox"];
  50. $indexBoxPhp = $_POST["indexdBox"];
  51. dbConnect($nameBoxPhp,$indexBoxPhp);
  52.  
  53.  
  54. function dbConnect($nameBox1, $indexBox1)
  55. {
  56. $servername ="localhost";
  57. $username="root";
  58. $password="";
  59. $dbname="student";
  60. //To create a connection
  61. $con = mysqli_connect($servername,$username,$password,$dbname);
  62.  
  63. //check connection
  64. if(!$con){
  65. die("Connection failed: ".mysqli_connect_error());
  66. }
  67.  
  68. $sql="SELECT * FROM StudentRec";
  69. $results=mysqli_query($con,$sql);
  70.  
  71. if(mysqli_num_rows($results)>0)
  72. {
  73. $row = mysqli_fetch_assoc($results);
  74. echo "Grade : ".$row['Grade'];
  75. }
  76. else
  77. {
  78. echo "Error: ".$sql."<br>".mysqli_error($con);
  79. }
  80. mysqli_close($con);
  81. }
  82.  
  83.  
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement