I am trying to write a simple PHP script:
- A user visits a webpage and registers their email address and a password via a form (no other iinputs required).
- Their email and password are stored in a database and a random unique 6 digit pin is generated and stored against the email. The pin is checked against existing pins in the database to ensure it is unique.
- The pin is then displayed on the webpage and shown to the user following confirmation of their email and password submission.
TL;DR users sign up and get a unique pin.
I have the following PHP code, but it doesn'nt seem to execute on my WAMP server. It just returns the .php pages as raw text. Am I missing some obvious syntax or configuration?
<?
if($_POST['srSubmit'] && $_POST['srEmail'] && $_POST['srPass']) {
$conn = mysql_connect('localhost','','');
mysql_select_db("db_test",$conn);
while(1) {
$pin = rand(111111,999999);
$sel = mysql_query("SELECT * FROM formusers WHERE pin = '$pin'");
if(mysql_num_rows($sel) != 0) { continue; }
mysql_query("INSERT INTO formusers(email,password,pin) VALUES('".$_POST['srEmail']."','".$_POST['srPass']."','".$pin."')");
if(mysql_affected_rows()!=-1) {
echo "Pin:" . $pin;
exit;
} else {
echo "Existing email, try again<br />";
}
break;
}
}
?>
<form method="POST" action="">
<input type="email" name="srEmail" value="" placeholder="Email" /><br />
<input type="password" name="srPass" value="" placeholder="Password" /><br />
<input type="submit" name="srSubmit" value="Register" />
</form>