Hey everyone!

I am fairly new to the php world but I am a quick learner when shown the right thing. I have a membership area sort of set up on my localhost in Easy PHP, and there is this Fatal Error that reads: "Fatal error: Cannot redeclare makeRandomPassword() (previously declared in C:\Program Files (x86)\EasyPHP-\www\Test\Scripts\register.php:76) in C:\Program Files (x86)\EasyPHP-\www\Test\Scripts\register.php on line 88"
Any help would be greatly appreciated! :) Thanks!
Here is the register.php code:


include 'C:\Program Files (x86)\EasyPHP-\www\Test\Scripts\register.php';

// Define post fields into simple variables
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
$info = $_POST['info'];

/* Let's strip some slashes in case the user entered
any escaped characters. */

$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
$info = stripslashes($info);

/* Do some error checking on the form posted fields */

if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
	print "You did not submit the following required information! <br />";
		echo "First Name is a required field. Please enter it below.<br />";
		echo "Last Name is a required field. Please enter it below.<br />";
		echo "Email Address is a required field. Please enter it below.<br />";
		echo "Desired Username is a required field. Please enter it below.<br />";
	include 'Register1.html'; // Show the form again!
	/* End the error checking and if everything is ok, we'll move on to
	 creating the user account */
	exit(); // if the error checking has failed, we'll exit the script!

/* Let's do some checking and ensure that the user's email address or username
 does not exist in the database */
 $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");
 $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
 $email_check = mysql_num_rows($sql_email_check);
 $username_check = mysql_num_rows($sql_username_check);
 if(($email_check > 0) || ($username_check > 0)){
 	echo "Please fix the following errors: <br />";
 	if($email_check > 0){
 		echo "<strong>Your email address has already been used by another member in our database. Please submit a different Email address!<br />";
 	if($username_check > 0){
 		echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />";
 	include 'Register1.html'; // Show the form again!
 	exit();  // exit the script so that we do not create this account!
/* Everything has passed both error checks that we have done.
It's time to create the account! */

/* Random Password generator. 

We'll generate a random password for the
user and encrypt it, email it and then enter it into the db.

function makeRandomPassword() {
  $salt = "abchefghjkmnpqrstuvwxyz0123456789";
  	$i = 0;
	$pass = '';
  	while ($i <= 7) {
    		$num = rand() % 33;
    		$tmp = substr($salt, $num, 1);
    		$pass = $pass . $tmp;
  	return $pass;

$random_password = makeRandomPassword();

$db_password = md5($random_password);

// Enter info into the Database.
$info2 = htmlspecialchars($info);
$sql = "INSERT INTO `users` 
		(`first_name`, `last_name`, `email_address`, `username`, `password`, `info`, `signup_date`) 
	values  ('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$info', now())"; 
mysql_query($sql) or die(mysql_error());

	echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
	$userid = mysql_insert_id();
	// Let's mail the user!
	$subject = "Your Membership for Ready Or Not! Tahirih's Website!";
	$message = "Dear $first_name $last_name,
	Thank you for registering at my website, http://www.tpelle.com!
	You are two steps away from logging in and interacting wiht my site.
	To activate your membership, please click here: http://www.tpelle.com/Scripts/activate.php?id=$userid&code=$db_password
	Once you activate your memebership, you will be able to login with the following information:
	Username: $username
	Password: $random_password
	This is an automated response, please do not reply!";
	mail($email_address, $subject, $message, "From: Tahirih Pellegrino<tcpelle5@gmail.com>\nX-Mailer: PHP/" . phpversion());
	echo 'Your membership information has been mailed to your email address! Please check your emain and follow the instructions!';


Recommended Answers

All 7 Replies

"Fatal error: Cannot redeclare makeRandomPassword() (previously declared in C:\Program Files (x86)\EasyPHP-\www\Test\Scripts\register.php:76) in C:\Program Files (x86)\EasyPHP-\www\Test\Scripts\register.php on line 88"

The function you declare on line 88 is already declared in your register.php. If you really need that function, give it another name. If it is the same as in register.php remove it.

Hello geneh23,

Initially I was also facing same issue with makeRandomPassword() like you beacuse
I defined & called makeRandomPassword() in a while loop to insert multiple users.
Then I defined makeRandomPassword() outside while loop & only called that makeRandomPassword() function using $random_password = makeRandomPassword() in a while loop;

Now it works well & uploded users using csv file.


@Nalini: Sorry for being a noob at this sort of thing but what do I need to do, that you did to fix the issue?

Just follow pritaeas's reply .

Okay, I am obviously not getting something..I am looking back at my code and I don't see how I am "re-declaring" this function with later on, I assign it a new variable..which would obviously mean it is something else now...so confused....

I figured it out!! ..well with the help of Nalini and pritaeas!

Thanks and sorry for the dumbness of my brain

No one is perfect in this world,I think there is too much things to learn by which we can improve ourself.So don't think about dumbness & all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.