Guest User

Untitled

a guest
Jul 20th, 2012
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1.  
  2. <?php
  3. define("SQL_HOST", "localhost");
  4. define("SQL_DATABASE", "test");
  5. define("SQL_USERNAME", "root");
  6. define("SQL_PASSWORD", "");
  7. //Change the above variables to your own
  8. define("MYPASSWORDSHA1", "my sha1 password salt");
  9. //Current password is sha1('password') so you should go to an online SHA1 generator and
  10. //generate a better password for your admin page.
  11.  
  12. if(!isset($_POST['password'])) //If they have not entered a password
  13. {
  14. echo "<h1>Administration</h1><br />
  15. <form action='admin.php' method='post'>
  16. Password: <input name='password' type='password' maxlength='500'><br />
  17. <input name='submit' type='submit'>
  18. </form>";
  19. }
  20. if(isset($_POST['password'])) //If they have entered a password
  21. {
  22. $password = sha1($_POST['password']); //Make input SAH1
  23. if($password != MYPASSWORDSHA1) die("Incorrect Password"); //Compare
  24. else
  25. {
  26. $con = mysql_connect(SQL_HOST, SQL_USERNAME, SQL_PASSWORD); //Connect to the SQL server
  27. mysql_select_db(SQL_DATABASE, $con); //Connect to the SQL DB
  28. $result = mysql_query("SELECT * FROM info"); //Select the whole table
  29. echo "<h1>Information de la base de donnée</h1><br /><table width='900'><tr><td>Prenom</td><td>Email</td><td>Reponse</td></tr>"; //Create the first line telling us what easy collumn is
  30. while($values = mysql_fetch_assoc($result))
  31. {
  32. echo "<tr><td>" . $values['nom'] . "</td><td>" . $values['email'] . "</td><td>" . $values['reponse'] . "</td></tr>"; //We echo the whole SQL table into a table :)
  33. }
  34. echo "</table>";
  35. mysql_close($con);
  36. }
  37. }
  38. ?>
  39.  
  40.  
  41. and my index.php
  42.  
  43. <?php
  44. define("SQL_HOST", "localhost");
  45. define("SQL_DATABASE", "test");
  46. define("SQL_USERNAME", "root");
  47. define("SQL_PASSWORD", "");
  48.  
  49. //Above you change localhost, testx, root, etc to your own database information
  50.  
  51. if(!isset($_POST['nom']) && !isset($_POST['email']) && !isset($_POST['box'])) //If the info hasn't been submitted
  52. {
  53. //Apply the information inserting page
  54. echo
  55. "
  56. <h1>Enter your info</h1><br />
  57. <form action='index.php' method='post'>
  58. Name: <input name='nom' type='text' size='30' maxlength='100' /><br />
  59. Email: <input name='email' type='text' size='30' maxlength='200' /><br />
  60. Colour:
  61. <select name='reponse'>
  62. <option value='blue'>Blue</option>
  63. <option value='green'>Green</option>
  64. <option value='orange'>Orange</option>
  65. <option value='black'>Black</option>
  66. </select><br />
  67. <input name='submit' type='submit'>
  68. </form>
  69. ";
  70. }
  71. else if(isset($_POST['name']))
  72. {
  73. //Sanitize our strings
  74. $name = htmlentities(mysql_escape_string($_POST['nom']));
  75. $email = htmlentities(mysql_escape_string($_POST['email']));
  76. if(!filter_var($email, FILTER_VALIDATE_EMAIL)) die("Invalid email"); //Check for a valid email
  77. $colour = htmlentities(mysql_escape_string($_POST['reponse']));
  78. $con = mysql_connect(SQL_HOST, SQL_USERNAME, SQL_PASSWORD); //Connect to the SQL server
  79. mysql_select_db(SQL_DATABASE, $con); //Connect to the DB
  80. $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
  81. if(mysql_num_rows($result) != 0) echo("You have already submitted your name and email!");//Tells them they already have submitted
  82. else
  83. {
  84. mysql_query("INSERT INTO info (nom, email, reponse) VALUES ('$nom', '$email', '$reponse')"); //Insert into DB
  85. echo "Information submitted!";
  86. }
  87. mysql_close($con);
  88. }
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment