Guest User

Untitled

a guest
Jul 20th, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2. define("SQL_HOST", "localhost");
  3. define("SQL_DATABASE", "test");
  4. define("SQL_USERNAME", "root");
  5. define("SQL_PASSWORD", "");
  6.  
  7. //Above you change localhost, test, root, etc to your own database information
  8.  
  9. if(!isset($_POST['nom']) && !isset($_POST['email']) && !isset($_POST['box'])) //If the info hasn't been submitted
  10. {
  11. //Apply the information inserting page
  12. echo
  13. "
  14. <h1>Enter your info</h1><br />
  15. <form action='index.php' method='post'>
  16. Name: <input name='nom' type='text' size='30' maxlength='100' /><br />
  17. Email: <input name='email' type='text' size='30' maxlength='200' /><br />
  18. Colour:
  19. <select name='reponse'>
  20. <option value='blue'>Blue</option>
  21. <option value='green'>Green</option>
  22. <option value='orange'>Orange</option>
  23. <option value='black'>Black</option>
  24. </select><br />
  25. <input name='submit' type='submit'>
  26. </form>
  27. ";
  28. }
  29. else if(isset($_POST['name']))
  30. {
  31. //Sanitize our strings
  32. $name = htmlentities(mysql_escape_string($_POST['nom']));
  33. $email = htmlentities(mysql_escape_string($_POST['email']));
  34. if(!filter_var($email, FILTER_VALIDATE_EMAIL)) die("Invalid email"); //Check for a valid email
  35. $colour = htmlentities(mysql_escape_string($_POST['reponse']));
  36. $con = mysql_connect(SQL_HOST, SQL_USERNAME, SQL_PASSWORD); //Connect to the SQL server
  37. mysql_select_db(SQL_DATABASE, $con); //Connect to the DB
  38. $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
  39. if(mysql_num_rows($result) != 0) echo("You have already submitted your name and email!");//Tells them they already have submitted
  40. else
  41. {
  42. mysql_query("INSERT INTO info (nom, email, reponse) VALUES ('$nom', '$email', '$reponse')"); //Insert into DB
  43. echo "Information submitted!";
  44. }
  45. mysql_close($con);
  46. }
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment