Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- index.html
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <link rel="stylesheet" href="style.css" />
- <title>Saving data to MySQL</title>
- </head>
- <body>
- <div class="container">
- <div class="content">
- <form id="reg_form" name="reg_form" method="post" action="register.php">
- <fieldset>
- <legend>Fan Registration</legend>
- User ID: <input type="text" name="userID" id="userID" /> <br /><br />
- First Name: <input type="text" name="fname" id="fname" />
- <br /><br />
- Last Name:
- <input type="text" name="lname" id="lname" /><br /><br />
- Email: <input type="text" name="email" id="email" /> <br /><br />
- <input type="submit" value="Register" />
- </fieldset>
- </form>
- </div>
- </div>
- </body>
- </html>
- fans.html
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <form id="fan" method="post" action="N3.php">
- User ID:
- <input type="text" name="user" id="user">
- <br><br>
- First Name:
- <input type="text" name="fname" id="fname">
- <br><br>
- Last Name:
- <input type="text" name="lname" id="lname">
- <br><br>
- Email:
- <input type="email" name="email" id="email">
- </form>
- </body>
- </html>
- register.php
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Data</title>
- </head>
- <body>
- <?php
- //establish connection and select the database as shown previously
- //retrieve form data and store them in PHP variables
- $userID = $_POST["userID"];
- $fname = $_POST["fname"];
- $lname = $_POST["lname"];
- $email = $_POST["email"];
- echo "Welcome $fname. Thank you for joining our fan club. <br>";
- //store our connection credentials in variables;
- $server = 'localhost';
- $user = 'root';
- $pass = '';
- //there is no password for the my current setup of MySQL
- $dbase = 'ITEC244';
- //make the actual connection to myaql and the chosen database
- $conn = mysqli_connect($server, $user, $pass, $dbase);
- //if the connection failed print error message
- if (!$conn) {
- die('Could not connect to database because: ' . mysqli_connect_error());
- }
- else echo "You are successfully connected to $dbase";
- //use PHP variables as input to MqSQL query.
- $qry = "INSERT INTO fans (userID, fname, lname, email) VALUES ('$userID', '$fname', '$lname', '$email');"; //only quote text data
- //use double quotes on the outside and single quotes on the inside
- //execute the query
- $result = mysqli_query($conn, $qry);
- $qry = "INSERT INTO fans (userID, fname, lname, email) VALUES ('trini_gal', 'Jessie', 'Alexis', 'trini_jess@live.com')";
- //execute the query
- $result = mysqli_query($conn, $qry);
- //check on the success of the query
- if($result) echo 'record successfully inserted.<br><br>';
- else echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';
- //close the connection
- mysqli_close($conn);
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement