Advertisement
thotfrnk

week5.php & html

Oct 14th, 2023
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.34 KB | None | 0 0
  1. index.html
  2. <!DOCTYPE html>
  3. <html lang="en">
  4.   <head>
  5.     <meta charset="UTF-8" />
  6.     <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  7.     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  8.     <link rel="stylesheet" href="style.css" />
  9.     <title>Saving data to MySQL</title>
  10.   </head>
  11.   <body>
  12.     <div class="container">
  13.       <div class="content">
  14.         <form id="reg_form" name="reg_form" method="post" action="register.php">
  15.           <fieldset>
  16.             <legend>Fan Registration</legend>
  17.             User ID: <input type="text" name="userID" id="userID" /> <br /><br />
  18.             First Name: <input type="text" name="fname" id="fname" />
  19.             <br /><br />
  20.             Last Name:
  21.             <input type="text" name="lname" id="lname" /><br /><br />
  22.             Email: <input type="text" name="email" id="email" /> <br /><br />
  23.             <input type="submit" value="Register" />
  24.           </fieldset>
  25.         </form>
  26.       </div>
  27.     </div>
  28.   </body>
  29. </html>
  30.  
  31. fans.html
  32. <!DOCTYPE html>
  33. <html lang="en">
  34. <head>
  35.   <meta charset="UTF-8">
  36.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  37.   <title>Document</title>
  38. </head>
  39. <body>
  40.   <form id="fan" method="post" action="N3.php">
  41.     User ID:
  42.     <input type="text" name="user" id="user">
  43.     <br><br>
  44.     First Name:
  45.     <input type="text" name="fname" id="fname">
  46.     <br><br>
  47.     Last Name:
  48.     <input type="text" name="lname" id="lname">
  49.     <br><br>
  50.     Email:
  51.     <input type="email" name="email" id="email">
  52.   </form>
  53. </body>
  54. </html>
  55.  
  56. register.php
  57. <!DOCTYPE html>
  58. <html lang="en">
  59. <head>
  60.   <meta charset="UTF-8">
  61.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  62.   <title>Data</title>
  63. </head>
  64. <body>
  65. <?php  
  66. //establish connection and select the database as shown previously
  67. //retrieve form data and store them in PHP variables
  68. $userID = $_POST["userID"];
  69. $fname = $_POST["fname"];
  70. $lname = $_POST["lname"];
  71. $email = $_POST["email"];
  72. echo "Welcome $fname. Thank you for joining our fan club. <br>";
  73.  
  74.  
  75. //store our connection credentials in variables;  
  76. $server = 'localhost';  
  77. $user = 'root';  
  78. $pass = '';
  79. //there is no password for the my current setup of MySQL  
  80. $dbase = 'ITEC244';      
  81. //make the actual connection to myaql and the chosen database  
  82. $conn = mysqli_connect($server, $user, $pass, $dbase);  
  83.  //if the connection failed print error message
  84.  if (!$conn) {    
  85.     die('Could not connect to database because: ' . mysqli_connect_error());    
  86.  }  
  87.   else echo "You are successfully connected to $dbase";
  88.  
  89. //use PHP variables as input to MqSQL query.
  90. $qry = "INSERT INTO fans (userID, fname, lname, email) VALUES ('$userID', '$fname', '$lname', '$email');";  //only quote text data
  91. //use double quotes on the outside and single quotes on the inside
  92.  
  93. //execute the query    
  94. $result = mysqli_query($conn, $qry);
  95.  
  96. $qry = "INSERT INTO fans (userID, fname, lname, email) VALUES ('trini_gal', 'Jessie', 'Alexis', 'trini_jess@live.com')";
  97. //execute the query    
  98. $result = mysqli_query($conn, $qry);
  99.  
  100. //check on the success of the query
  101.  if($result) echo 'record successfully inserted.<br><br>';
  102.   else echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';  
  103.  //close the connection
  104.  mysqli_close($conn);
  105.  
  106. ?>
  107. </body>
  108. </html>
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement