Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start();
- $_SESSION['username'] = $_POST["user_name"];
- ?>
- <html>
- <head>
- <title>Test Registration</title>
- </head>
- <body>
- <form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
- <?php
- $name_good = false;
- $email_good = false;
- $pass_good = false;
- // Check if $username is set if so check $username against conditions if false echo error if true echo $username.
- if (isset($_POST["user_name"])) {
- if (strlen($_POST["user_name"]) < 3 || strlen($_POST["user_name"]) > 20 ) {
- echo "<p><font color=\"red\">*</font> Student's Name: <input type=\"text\" name=\"user_name\" value=\"".$_POST["user_name"]."\" /> <font color='red'>Your username must be more than 3 characters and less than 20.</font>"."</p>";
- } else {
- $name_good = $_POST["user_name"];
- }
- } else {
- echo "<p><font color=\"red\">*</font> Student's Name: <input type=\"text\" name=\"user_name\" /></p>";
- }
- // Check if $useremail is set if so check if userconemail matches if not show error then check if useremail contains @ if not show an error.
- if (isset($_POST["user_email"])) {
- if (strcmp($_POST["user_email"], $_POST["user_con_email"])) {
- echo "<p><font color=\"red\">*</font> Parent's Email: <input type=\"text\" name=\"user_email\" size=\"40\" value=\"".$_POST["user_email"]."\" /> <font color='red'>Your Emails do not match, silly goose.</font>"."<br>";
- } elseif (stristr($_POST["user_email"], '@')) {
- $email_good = $_POST["user_email"];
- }
- } else {
- echo "<p><font color=\"red\">*</font> Parent's Email: <input type=\"text\" name=\"user_email\" size=\"40\" /></p>"."<p><font color=\"red\">*</font> Confirm Email: <input type=\"text\" name=\"user_con_email\" size=\"40\" /></p>";
- }
- // Check $userpass is set as well as more than 8 characters and if $userpass and $userconpass match if not shows errors.
- if (isset($_POST["user_pass"])) {
- if (strcmp($_POST["user_pass"], $_POST["user_con_pass"])) {
- echo "<font color=\"red\">*</font> Password: <input type=\"text\" name=\"user_pass\" value=\"".$_POST["user_pass"]."\" /> <font color='red'>Your Passwords do not match silly goose.</font>"."</br>";
- } elseif (strlen($_POST["user_pass"]) < 8 ) {
- echo "<font color=\"red\">*</font> Password: <input type=\"text\" name=\"user_pass\" value=\"".$_POST["user_pass"]."\" /> <font color='red'>Your Password must be at least 8 characters.</font>"."<br>";
- } else {
- $pass_good = $_POST["user_pass"];
- }
- } else {
- echo "<p><font color=\"red\">*</font> Student Password: <input type=\"password\" name=\"user_pass\" /></p>"."<p><font color=\"red\">*</font> Confirm Password: <input type=\"password\" name=\"user_con_pass\" /></p>"."<br>";
- }
- if ($name_good && $email_good && $pass_good) {
- // Creat a variable to hold the query to issue, which will insert data into the database.
- $do_sql = "INSERT INTO `user_db`.`user_info` ( `user_name`, `user_email`, `user_pass` ) VALUES ('$name_good', '$email_good', '$pass_good')";
- // Add the connection information, add the die() function to end the script and display the mysql_error() function if the connection can not be made.
- $connection = @mysql_connect("localhost", "chacho", "mysqltraining")
- or die(mysql_error());
- // Issue a query using the mysql_query() function. include the @ to supress warnings, as well as the die() function to cause the script to end and a message to display if the query fails.
- $created = @mysql_query($do_sql, $connection) or die(mysql_error());
- }
- // Test the value of $created. If it's true, the query was successful, and a variable is created to hold the message, "Database has been created".
- if (isset($created)) {
- header("location: test_profile.php");
- }
- ?>
- <a href=/new_test.php>Resubmit Form</a> <input type="submit" name="submit" value="Submit">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement