Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define("SQL_HOST", "localhost");
- define("SQL_DATABASE", "test");
- define("SQL_USERNAME", "root");
- define("SQL_PASSWORD", "");
- //Above you change localhost, test, root, etc to your own database information
- if(!isset($_POST['nom']) && !isset($_POST['email']) && !isset($_POST['box'])) //If the info hasn't been submitted
- {
- //Apply the information inserting page
- echo
- "
- <h1>Enter your info</h1><br />
- <form action='index.php' method='post'>
- Name: <input name='nom' type='text' size='30' maxlength='100' /><br />
- Email: <input name='email' type='text' size='30' maxlength='200' /><br />
- Colour:
- <select name='reponse'>
- <option value='blue'>Blue</option>
- <option value='green'>Green</option>
- <option value='orange'>Orange</option>
- <option value='black'>Black</option>
- </select><br />
- <input name='submit' type='submit'>
- </form>
- ";
- }
- else if(isset($_POST['name']))
- {
- //Sanitize our strings
- $name = htmlentities(mysql_escape_string($_POST['nom']));
- $email = htmlentities(mysql_escape_string($_POST['email']));
- if(!filter_var($email, FILTER_VALIDATE_EMAIL)) die("Invalid email"); //Check for a valid email
- $colour = htmlentities(mysql_escape_string($_POST['reponse']));
- $con = mysql_connect(SQL_HOST, SQL_USERNAME, SQL_PASSWORD); //Connect to the SQL server
- mysql_select_db(SQL_DATABASE, $con); //Connect to the DB
- $result = mysql_query("SELECT name FROM info WHERE email='$email' AND name='$nom'"); //Checks if there is someone with the same name and email already
- if(mysql_num_rows($result) != 0) echo("You have already submitted your name and email!");//Tells them they already have submitted
- else
- {
- mysql_query("INSERT INTO info (nom, email, reponse) VALUES ('$nom', '$email', '$reponse')"); //Insert into DB
- echo "Information submitted!";
- }
- mysql_close($con);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment