Jump to content

Checking function true or false


Lassie

Recommended Posts

I have a function and need to establish whether it executed correctly and if show an error message.

I have the following to call the function and check the return, true or false.

Is this the way to go?

//new customer so create user account and password
			user_account($first_name,$last_name,$email);
			if (user_account($first_name,$last_name,$email)!=TRUE)
			{
				echo 'A system error occurred.Please contact eBooks4U ';
				exit();
			}



  //display cart, not allowing changes and without pictures 
      display_cart($_SESSION['cart'], false, 1);

 

The function is

function user_account($first_name,$last_name,$email)

{

//create short variables.

$fn=$first_name;

$ln=$last_name;

$e=$email;

 

//generate password

// Create a new, random password.

$p = substr ( md5(uniqid(rand(),1)), 3, 10);

//register details

if ($fn && $ln && $e && $p) { // If everything's OK.

 

//connect to db registration already connected?

$connection=reg_connect();

 

// Make sure the email address is available.Maybe already checked

$query = "SELECT user_id FROM users WHERE email='$e'";

$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());

 

if (mysql_num_rows($result) == 0) { // Available.

 

// Create the activation code.

$a = md5(uniqid(rand(), true));

//Modify update for password by taking out md5, already done.

 

// Add the user.

$query = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', md5('$p'), '$fn', '$ln', '$a', NOW() )";

$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());

 

if (mysql_affected_rows() == 1) { // If it ran OK.

 

//add from

$to = $_POST['email'];

$subj = "Activating Your Account";

$mess = "Thank you. You are now registered with e-Books4U<br />To activate your account, please click on this link;<br />\n\n";

$mess .="<a href='http://217.46.159.226/e_cart21/reg/activate.php?x=" . mysql_insert_id() ."&y=$a'>Activate account</a>";

$mess.="<br />Your password for login is, $p\n\n";

 

$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 

mail($to,$subj,$mess,$headers);

 

 

return true;

}else{

return false;

}

}

}

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.