Advertisement
Guest User

Untitled

a guest
May 11th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <h1>Add_data.php</h1>
  11.  
  12. <?php
  13. $servername = "localhost";
  14. $username = "root"; //root is default user
  15. $password = ""; //default pw is blank
  16. $dbName = "moviesdb"; //database name
  17.  
  18. //create connection
  19. $conn = mysqli_connect($servername, $username, $password, $dbName);
  20.  
  21. //check connection
  22. if(!$conn) {
  23. die("Connection Failed:" . mysqli_connect_error());
  24. }
  25. echo "Connected Successfully! <br>";
  26.  
  27. //get data from Form index.html
  28. $id = $_GET['MovieID'];
  29. $name = $_GET['MovieName'];
  30. $description = $_GET['MovieDescription'];
  31.  
  32. // $name = $_GET['name'];
  33. // $alterego = $_GET['alterego'];
  34. // $gender = $_GET['gender'];
  35. // $power = $_GET['power'];
  36.  
  37. //make sql insert statement
  38. $sql = "INSERT into movies(MoviesID, MovieName,MovieDescription)
  39. values(". $id .",'". $name ."','". $description ."');"
  40.  
  41. //write the data to the database
  42. if(mysqli_query($conn, $sql)){
  43. echo "<h1>Records ADDED successfully.<br>";
  44. echo "<a href='add_data.html'>ADD another?</a></h1>";
  45. }
  46. else {
  47. echo "<h1>ERROR: Unable to execute $sql. " . mysqli_error($conn);
  48. mysqli_error($conn);
  49. echo "<br><a href='add_data.html'>ADD another?</a></h1>";
  50. // echo "<h1><a href='displayinfo.php'>Display Records</a></h1>";
  51. }
  52.  
  53. mysqli_close($conn);
  54. ?>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement