BigTime Posted August 24, 2011 Share Posted August 24, 2011 Im trying to assign and update table rows with a random 9 character string but am receiving the error : Fatal error: Cannot redeclare make_seed() (previously declared in ... How can I clear/reset the value before the next loop else { while ($data=mysql_fetch_array($users)){ $user=$data[user]; $usersarray = array($users); foreach ($usersarray as $key => $u){ //clear pass $token = ""; srand(); //generate new password $password_length = 9; function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } srand(make_seed()); $alfa = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*(){}[]"; for($i = 0; $i < $password_length; $i ++) { $token .= $alfa[rand(0, strlen($alfa))]; } // insert password // setup SQL statement $SQL = " UPDATE data SET pass='$token' WHERE user='$m1' "; // execute SQL statement $makeit = mysql_db_query($userdb,"$SQL",$usercid); // check for error if (!$makeit) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 24, 2011 Share Posted August 24, 2011 Move the function out of the loop. Quote Link to comment Share on other sites More sharing options...
BigTime Posted August 24, 2011 Author Share Posted August 24, 2011 Hi Shawn, thank you. The entire purpose of the foreach loop is to create a unique entry for each record. If I move it out of the loop, then how do I get a new and unique entry for each record? I was hoping there was a way to reset/clear the function make_seed() declared value at the top or bottom of the loop am I going about this the wrong way? Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 24, 2011 Share Posted August 24, 2011 You need to move the function declaration out of the loop. You can only define a function once (as the error tells you), but you have it in a loop to declare it multiple times. Move this to the very bottom of your page outside of any loops: function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } Quote Link to comment Share on other sites More sharing options...
BigTime Posted August 24, 2011 Author Share Posted August 24, 2011 completely dint understand that when you first said it, but further explanation of course is a big DUH moment!! Thank you for your help, Shawn! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.