I have this code and couldn't get it to work:
$character_set_array = array();
$character_set_array[] = array('count' => 8, 'characters' => '0123456789');
$temp_array = array();
foreach ($character_set_array as $character_set) {
for ($i = 0; $i < $character_set['count']; $i++) {
$temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)];
}
}
shuffle($temp_array);
$pinstart = 'AA';
$pinend = implode('', $temp_array);
$newpin = $pinstart.$pinend;
function regenerate_pin($pin)
{
if ($PIN == 'PIN') { return ''; } else {
$pin = mysql_real_escape_string($pin); // SECURITY!
$result = mysql_query("SELECT pin FROM pins WHERE pin='$pin' LIMIT 1");
if(mysql_num_rows($result) == 0) {
return 'This pin has already been used';
} else {
$sql = mysql_query("UPDATE pins SET pins='$newpin'");
return "The pin has been regened, the new pin is '.$newpin.'";
} }
}
Basically what I'm trying to get it to do is this: - Get the pin from a HTML input box, - Check if the pin exists in the database (works) - If it exists, replace $pin with $newpin and print out the $newpin, this is how my table looks like
- Some info about my table:
- Table name = pins Column where pin is stored is named Pin
Thank you for reading and I hope I find a quick solution.