Jump to content

Problems passing userid after database insert and email


sssteeve

Recommended Posts

This is a form processing script I am using. I am trying to pass the userid (created by mysql on insert) and I can get it to work in the email sent to the user by the script but not in the redirect URL. Does anyone know how I can get this to work?

 

With best wishes.

 

Steven

 

<? 

include 'db.php'; 
# grab the POST variables from the HTML form, 
# put them into PHP variables so we can work with them  
$username = $_POST['username']; 
$email_address = $_POST['email_address']; 

# Any escaped characters? No, not a jailbreak...something that could 
# cause errors when PHP processes. We check for that here. 
$username = stripslashes($username); 
$email_address = stripslashes($email_address); 

# Any errors in the posted fields? Lets check... 
# If there is an error, then we show the join form again 
# so they can fill it out again. If everything 
# checks out, then go ahead.
if((!$username) || (!$email_address)){ 
    echo 'You did not submit the following required information! <br />'; 
      if(!$username){ 
        echo "Full Name is a required field. Please enter it below.<br />"; 
    } 
if(!$email_address){ 
        echo "Email Address is a required field. Please enter it below.<br />"; 
    } 

    include 'index.php'; 
    exit(); 
} 
     
# does this user already exist in the database? lets check for that now...  
$sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'"); 
  
$email_check = mysql_num_rows($sql_email_check); 

  
if(($email_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 use a different Email address!<br />"; 
         unset($email_address); 
     }
     include 'index.php'; // Show the form again! 
     exit(); 
} 
  
# everything checks out so far, so lets add this user! 

$sql = mysql_query("INSERT INTO users (username, email_address, signup_date)  
  VALUES('$username', '$email_address', now())") or die (mysql_error()); 

if(!$sql){ 
    echo 'There has been an error creating your account.'; 
} else { 
    $userid = mysql_insert_id(); 
    // Let's mail the user! 
    $subject = "My Website - Important Information"; 
    $message = "Thank you for registering at My Website. http://www.myurl.com
     
Please click the link below to complete your registration. 

http://www.myurl.com/enter.php?id=$userid
     
My Website
http://www.myurl.com
     
This is an automated response, please do not reply!"; 
     
    mail($email_address, $subject, $message, "From: My Website <[email protected]>\nX-Mailer: PHP/" . phpversion()); 
  
    header( 'Location: http://www.myurl.com/thanks.php?id=$userid' );
} 
?> 

    header( 'Location: http://www.myurl.com/thanks.php?id=$userid' );

You used single quotes instead of double quotes which will output http://www.myurl.com/thanks.php?id=$userid instead of http://www.myurl.com/thanks.php?id=1

 

Single quotes do not allow you to use variables in them.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.