Guest User

Untitled

a guest
Aug 9th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. <?php
  2.  
  3. $hostname = "localhost"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost
  4. $db_user = "*******"; // change to your database password
  5. $db_password = "*******"; // change to your database password
  6. $database = "smislich"; // provide your database name
  7. $db_table = "Superhero"; // leave this as is
  8.  
  9.  
  10.  
  11. $db = mysql_connect($hostname, $db_user, $db_password);
  12. mysql_select_db($database,$db);
  13. ?>
  14. <html>
  15. <head>
  16. <title>Superhero Form</title>
  17. </head>
  18. <body>
  19.  
  20. <?php
  21. if (isset($_REQUEST['Submit'])) {
  22. # THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE
  23. $sql = "INSERT INTO $db_table(FirstName, LastName, HeroName, PictureLink, Publisher, Power) values ('".mysql_real_escape_string(stripslashes($_REQUEST['firstname']))."','".mysql_real_escape_string(stripslashes($_REQUEST['lastname']))."','".mysql_real_escape_string(stripslashes($_REQUEST['heroname']))."','".mysql_real_escape_string(stripslashes($_REQUEST['picturelink']))."','".mysql_real_escape_string(stripslashes($_REQUEST['publisher']))."','".mysql_real_escape_string(stripslashes(implode(',',$_REQUEST['power'])))."')";
  24. if($result = mysql_query($sql ,$db)) {
  25. echo '<h1>Thank you</h1>Your information has been entered into our database.<br><form method="link" action="dbm2.php"><input type="submit" value="See database">
  26. </form>';
  27.  
  28. } else {
  29. echo "ERROR: ".mysql_error();
  30. }
  31. } else {
  32. ?>
  33. <h1>Enter New Superhero Information</h1>
  34. <form method="post" action="">
  35. First:<br>
  36. <input type="text" name="firstname">
  37. <br>
  38. Last: <br>
  39. <input type="text" name="lastname">
  40. <br>
  41. Hero Name:<br>
  42. <input type="text" name="heroname">
  43. <br>
  44. Picture:<br>
  45. <input type="text" name="picturelink">
  46. <br>
  47. Publisher:<br>
  48. <select name= "publisher">
  49. <option value="DC">DC</option>
  50. <option value="Marvel">Marvel</option>
  51. <option value="Other">Other</option>
  52. </select>
  53. <br>
  54. Power:<br>
  55. <select name="power[]" size="11" multiple>
  56. <option value="Strength">Super Strength</option>
  57. <option value="Bouncing">Bouncing</option>
  58. <option value="Flying">Flying</option>
  59. <option value="Speed">Speed</option>
  60. <option value="Immortality">Immortality</option>
  61. <option value="X-Ray Vision">X-Ray Vision</option>
  62. <option value="Morphing">Morphing</option>
  63. <option value="Swimming">Swimming</option>
  64. <option value="Invisibility">Invisibility</option>
  65. <option value="Amputation">Amputation</option>
  66. <option value="Intelligence">Super Intelligence</option>
  67. </select>
  68. <br>
  69. <br>
  70. <input type="submit" name="Submit" value="Submit">
  71. </form>
  72. <?php
  73. }
  74. ?>
  75. </body>
  76. </html>
Add Comment
Please, Sign In to add comment