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", "");
- //Change the above variables to your own
- define("MYPASSWORDSHA1", "my sha1 password salt");
- //Current password is sha1('password') so you should go to an online SHA1 generator and
- //generate a better password for your admin page.
- if(!isset($_POST['password'])) //If they have not entered a password
- {
- echo "<h1>Administration</h1><br />
- <form action='admin.php' method='post'>
- Password: <input name='password' type='password' maxlength='500'><br />
- <input name='submit' type='submit'>
- </form>";
- }
- if(isset($_POST['password'])) //If they have entered a password
- {
- $password = sha1($_POST['password']); //Make input SAH1
- if($password != MYPASSWORDSHA1) die("Incorrect Password"); //Compare
- else
- {
- $con = mysql_connect(SQL_HOST, SQL_USERNAME, SQL_PASSWORD); //Connect to the SQL server
- mysql_select_db(SQL_DATABASE, $con); //Connect to the SQL DB
- $result = mysql_query("SELECT * FROM info"); //Select the whole table
- 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
- while($values = mysql_fetch_assoc($result))
- {
- echo "<tr><td>" . $values['nom'] . "</td><td>" . $values['email'] . "</td><td>" . $values['reponse'] . "</td></tr>"; //We echo the whole SQL table into a table :)
- }
- echo "</table>";
- mysql_close($con);
- }
- }
- ?>
- and my index.php
- <?php
- define("SQL_HOST", "localhost");
- define("SQL_DATABASE", "test");
- define("SQL_USERNAME", "root");
- define("SQL_PASSWORD", "");
- //Above you change localhost, testx, 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