Jump to content

PHP Email confirmation, adding value


ryanwood4

Recommended Posts

I have this php code, which allows members to sign-up, and then receive an email containing their details.

 

However, I want the email to contain their member ID, this figure is automatically created in the MySQL table as an auto-increment primary key. How do I add this to the email?

 

<?php 

// Connects to your Database 
mysql_connect("xxxx", "xxxx", "xxxx") or die(mysql_error()); 
mysql_select_db("f1times_comp") or die(mysql_error());  

//This code runs if the form has been submitted
if (isset($_POST['submit'])) { 

//This makes sure they did not leave any fields blank
if (!$_POST['forename'] | !$_POST['surname'] | !$_POST['email']) {
die('You did not complete all of the required fields. Click back in your browser to return.');
}

// checks if the email is in use
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$usercheck = $_POST['email'];
$check = mysql_query("SELECT email FROM member_id WHERE email = '$usercheck'") 
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the email exists it gives an error
if ($check2 != 0) {
die('Sorry, the email '.$_POST['email'].' is already in use. Click back in your browser to return.');
}

// now we insert it into the database
$insert = "INSERT INTO member_id (forename, surname, email)
VALUES ('$_POST[forename]','$_POST[surname]','$_POST[email]')";
$add_member = mysql_query($insert);

$email = $_POST["email"];
$forename = $_POST["forename"];
$surname = $_POST["surname"];

$to = "$email";
$subject = "The F1 Times - Member ID";
$MsgHeader = "From: The F1 Times <ryan@f1times.co.uk>\n";
$MsgHeader .= "MIME-Version: 1.0\n";
$MsgHeader .= "Content-type: text/html; charset=iso-8859-1";
$MsgBody = "
<html>
<head>
<title>Your Member ID</title>
</head>
<body>

<table style='padding-left:0px' style='padding-top:0px'>
<tr><td align='left'><img src='http://www.website.com/pix/logo.gif'></td></tr>
</table>
<table style='margin-left:12px'>  
<tr><td> </td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>$forename, your registration has been received by Sherbet Clothing.</font></td></tr>
<tr><td> </td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Your Email: $email</font></td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Your Member ID: $member_id</font></td></tr>
<tr><td> </td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Best Regards</font></td></tr>
<tr><td> </td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>The F1 Times</font></td></tr>
<tr><td> </td></tr>
<tr><td><font style='font-size: 11px' style='font-family: Tahoma, Arial'>This message has been automatically generated please do not reply.</font></td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
<table style='margin-left:12px' style='margin-right:250px'>
<tr><td><font style='color: #336699' style='font-size: 10px' style='font-family: Tahoma, Arial'>This message, and any attachments, is intended only for the use of the individual or entity to which it is addressed, and may contain confidential, proprietary and/or privileged information that is exempt from disclosure under applicable law which is not waived or lost by any transmission failure. 
If the reader of this message is not the intended recipient or its employee, or agent responsible for delivering the message to the intended recipient, you are hereby notified that any use, dissemination, distribution or copying of this communication and any attachments hereto is strictly prohibited. 
If you have received this communication in error, please destroy this message. 
Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorised to state them to be the views of another person or entity.</font></td></tr> 
</table>
</body>
</html>";
mail($to, $subject, $MsgBody, $MsgHeader);
?>

<p>You will shortly receive an email containing your information.</p>
<?php 
} 
else 
{	
?>

<div id="stylized" class="myform">
  <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <h1>Sign-up</h1>
    <label>First Name
        <span class="small">Enter your first name</span>
    </label>
    <input type="text" name="forename" id="textfield" />
    
    <label>Surname
        <span class="small">Your known as?</span>
    </label>
    <input type="text" name="surname" id="textfield" />
    
    <label>Email
        <span class="small">Enter a valid email</span>
    </label>
    <input type="text" name="email" id="textfield" />

    <button input type="submit" name="submit" value="Register">Register</button>
    <div class="spacer"></div>

</form>
</div>

<?php
}
?>

 

Thanks in advance.

Link to comment
Share on other sites

You could add it right after this:

// now we insert it into the database
$insert = "INSERT INTO member_id (forename, surname, email)
VALUES ('$_POST[forename]','$_POST[surname]','$_POST[email]')";
$add_member = mysql_query($insert);

 

That is where the query is actually made and the information is in the database, so right after that bit of code should work.

Link to comment
Share on other sites

Do the query I stated above and select the auto-incremented key(whatever that field is called) and do:

 

$memberQuery = SELECT FROM etc(query earlier)
$memberResults = mysql_fetch_assoc($memberQuery);

 

Then you can just do a $memberResults['member_id'];(Or whatever your auto-incremented key is called) to output the member id

Link to comment
Share on other sites

// now we insert it into the database
$insert = "INSERT INTO member_id (forename, surname, email)
VALUES ('$_POST[forename]','$_POST[surname]','$_POST[email]')";
$add_member = mysql_query($insert);

$memberQuery = SELECT member_id FROM member_id WHERE email='$email'
$memberResults = mysql_fetch_assoc($memberQuery);

$email = $_POST["email"];
$forename = $_POST["forename"];
$surname = $_POST["surname"];
$member_id = $_POST["member_id"];

 

This is what I have tried, but I get this: Parse error: syntax error, unexpected T_STRING in /home/f1times/public_html/mobile/sign_up1.php on line 34

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.