so i have this key giveaway script, now i want to get the displayed key deleted from the database. how do i get this to work within the code i wrote?
so $key is the key that will be send to you and display in the browser, but i want this key to get deleted out of the database after it is send and displayed so it cannot get shown a second time to another user.
<?php
//fill in mail
echo "
<form method='post' action=" . $_SERVER['PHP_SELF'] . ">
Email: <input name='email'></input><br>
<input type='submit' value='Get your key' name='submit'> </input><br><br>
</form>";
if(empty($_POST["email"]))
{
echo "Please enter an email adress.";
}
else{
// get key from database
$key = dispres();
//mail key to input mail
$to = $_POST["email"];
$subject = 'Your test key';
$message = 'Your key is: ' . $key;
$headers = 'There you go!';
mail($to, $subject, $message, $headers);
echo "Your code has been sent to your email: " . $_POST["email"] . " ";
echo $key;
}
function dispres(){
//database connect
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = 'pwd';
$database = 'c3keys';
$table = 'test';
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
//grab random key from database
$result = mysql_query("SELECT * FROM {$table} order by RAND() LIMIT 1");
$row = mysql_fetch_row($result);
$result = implode('|',$row);
return $result;
//delete key from database
//had this as a begin
mysqli_query("DELETE FROM test WHERE test='$key'");
//remember ip adress for 1 use only
}
?>