Advertisement
Guest User

form.php

a guest
Mar 10th, 2017
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.70 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <?php
  5. $servername = "sampledb";
  6. $username = "samplename";
  7. $password = "password";
  8. $dbname = "dbname";
  9.  
  10. $name=$_POST['name'];
  11. //echo $name;
  12.  
  13. $conn = mysqli_connect($servername, $username, $password, $dbname);
  14. // Check connection
  15. if (!$conn) {
  16. die("Connection failed: " . mysqli_connect_error());
  17. }
  18.  
  19. $sql = "CREATE TABLE Student_Records (fullname VARCHAR(30) NOT NULL, Student_ID INT (8) UNSIGNED, email VARCHAR (50), courses VARCHAR (300), grades VARCHAR(300));";
  20. $result = mysqli_query($conn, $sql);
  21.  
  22. $sql = "INSERT INTO Student_Records VALUES('Pamela Diaz','20175051','pamela1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : A, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : A, Writing, Speaking, Thinking II: A, Calculus I : C, Physics II : C');";
  23. $sql .= "INSERT INTO Student_Records VALUES('Angela Anderson','20175052','angela1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B, Writing, Speaking, Thinking I: D, Calculus I : A, Physics I : A, Introduction to Computer Science I : A, Writing, Speaking, Thinking II: A, Calculus I : C, Physics II : C+');";
  24. $sql .= "INSERT INTO Student_Records VALUES('James Diaz','20175053','james1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science II : C, Writing, Speaking, Thinking II: C, Calculus I : C, Physics I : D, Introduction to Computer Science I : A, Writing, Speaking, Thinking II: A, Calculus I : C, Physics II : C+');";
  25. $sql .= "INSERT INTO Student_Records VALUES('Todd Diaz','20175054','todd1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : D, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : A, Writing, Speaking, Thinking II: A, Calculus I : C, Physics II : C+');";
  26. $sql .= "INSERT INTO Student_Records VALUES('Ted Diaz','20175055','ted1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : D, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : A, Writing, Speaking, Thinking II: A, Calculus I : C, Physics II : C+');";
  27. $sql .= "INSERT INTO Student_Records VALUES('Jane Diaz','20175056','jane1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  28. $sql .= "INSERT INTO Student_Records VALUES('Beth Diaz','20175057','beth1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : C, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : F, Writing, Speaking, Thinking II: F, Calculus I : C, Physics II : C');";
  29. $sql .= "INSERT INTO Student_Records VALUES('Johnathan Diaz','20175058','johnathan1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : F, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : F, Writing, Speaking, Thinking II: D, Calculus I : C, Physics II : C');";
  30. $sql .= "INSERT INTO Student_Records VALUES('Jason Diaz','20175059','jason1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : C, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : C, Writing, Speaking, Thinking II: C, Calculus I : C, Physics II : C');";
  31. $sql .= "INSERT INTO Student_Records VALUES('Jennifer Diaz','20175060','jennifer1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : C, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : C, Writing, Speaking, Thinking II: B, Calculus I : C, Physics II : C');";
  32. $sql .= "INSERT INTO Student_Records VALUES('Edgar Diaz','20175061','edgar1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B, Writing, Speaking, Thinking II: B, Calculus I : C, Physics II : C');";
  33. $sql .= "INSERT INTO Student_Records VALUES('Ana Diaz','20175062','ana1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : F, Writing, Speaking, Thinking II: F, Calculus I : C, Physics II : C');";
  34. $sql .= "INSERT INTO Student_Records VALUES('Anna Diaz','20175063','anna1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : F, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : D, Writing, Speaking, Thinking II: D, Calculus I : C, Physics II : C');";
  35. $sql .= "INSERT INTO Student_Records VALUES('Bobby Diaz','20175064','bobby1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : A, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : A, Writing, Speaking, Thinking II: A, Calculus I : C, Physics II : C');";
  36. $sql .= "INSERT INTO Student_Records VALUES('Bob Diaz','20175065','bob1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : A, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : A, Writing, Speaking, Thinking II: A, Calculus I : C, Physics II : C');";
  37. $sql .= "INSERT INTO Student_Records VALUES('Jeff Diaz','20175066','jeff1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : A, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : A, Writing, Speaking, Thinking II: A, Calculus I : C, Physics II : C');";
  38. $sql .= "INSERT INTO Student_Records VALUES('Eddy Diaz','20175067','eddy1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : A, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : A, Writing, Speaking, Thinking II: A, Calculus I : C, Physics II : C');";
  39. $sql .= "INSERT INTO Student_Records VALUES('Aly Diaz','20175068','aly1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : A, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : A, Writing, Speaking, Thinking II: A, Calculus I : C, Physics II : C');";
  40. $sql .= "INSERT INTO Student_Records VALUES('Renee Diaz','20175069','renee1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  41. $sql .= "INSERT INTO Student_Records VALUES('Evan Diaz','20175070','evan1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  42. $sql .= "INSERT INTO Student_Records VALUES('Kenny Diaz','20175071','kenny1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  43. $sql .= "INSERT INTO Student_Records VALUES('Matt Diaz','20175072','matt1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  44. $sql .= "INSERT INTO Student_Records VALUES('Nick Diaz','20175073','nick1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  45. $sql .= "INSERT INTO Student_Records VALUES('Seth Diaz','20175074','seth1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  46. $sql .= "INSERT INTO Student_Records VALUES('Charlotte Diaz','20175075','charlotte1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  47. $sql .= "INSERT INTO Student_Records VALUES('Sasha Diaz','20175076','sasha1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  48. $sql .= "INSERT INTO Student_Records VALUES('Becky Diaz','20175077','becky1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  49. $sql .= "INSERT INTO Student_Records VALUES('Dean Diaz ','20175078','dean1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  50. $sql .= "INSERT INTO Student_Records VALUES('Brock Diaz','20175079','brock1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  51. $sql .= "INSERT INTO Student_Records VALUES('Randy Diaz','20175080','randy1@gmail.com','Introduction to Computer Science I, Writing, Speaking, Thinking II, Calculus I, Physics I','Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B, Calculus I : C, Physics I : B+, Introduction to Computer Science I : B+, Writing, Speaking, Thinking II: B+, Calculus I : C, Physics II : C');";
  52.  
  53. if ($conn->multi_query($sql) === TRUE) {
  54. echo "New records created successfully";
  55. //echo $sql;
  56. } else {
  57. echo "Error: " . $sql . "<br>" . $conn->error;
  58. }
  59.  
  60. $conn = new mysqli($servername, $username, $password, $dbname);
  61.  
  62. $sql = "SELECT * from Student_Records where fullname = '$name'";
  63. //echo $sql;
  64. $result=$conn->query($sql);
  65. if ($result->num_rows > 0) {
  66. $query = "SELECT * FROM Student_Records"; //You don't need a ; like you do in SQL
  67. //$result1 = mysqli_query($conn,$query);
  68. $result1=$conn->query($query);
  69. echo "<br><br><table>"; // start a table tag in the HTML
  70. while($row = $result1->fetch_assoc()){ //Creates a loop to loop through results
  71. echo "<tr><td>" . $row['fullname'] . "</td><td>" . $row['Student_ID'] . "</td><td>" . $row['email'] . "</td><td>" . $row['courses'] . "</td><td>" . $row['grades'] . "</td></tr>"; //$row['index'] the index here is a field name
  72. }
  73.  
  74. echo "</table>"; //Close the table in HTML
  75. }
  76. else{
  77. echo "not found";
  78. }
  79.  
  80. mysqli_close($conn);
  81. ?>
  82. </body>
  83. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement