ryanwood4 Posted August 28, 2009 Share Posted August 28, 2009 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. Quote Link to comment Share on other sites More sharing options...
ReKoNiZe Posted August 28, 2009 Share Posted August 28, 2009 You will need to query what you just inserted. So you could do: SELECT member_id FROM member_id WHERE email='$email' Then just do a mysql_fetch_array() on the query and spit out the member_id Quote Link to comment Share on other sites More sharing options...
ryanwood4 Posted August 28, 2009 Author Share Posted August 28, 2009 Thanks, but where abouts do I add this? Quote Link to comment Share on other sites More sharing options...
ReKoNiZe Posted August 28, 2009 Share Posted August 28, 2009 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. Quote Link to comment Share on other sites More sharing options...
ryanwood4 Posted August 28, 2009 Author Share Posted August 28, 2009 Would you mind elaborating on the code I need to insert a little. Im pretty useless with PHP, everything I tried, doesn't seem to work. Quote Link to comment Share on other sites More sharing options...
ReKoNiZe Posted August 28, 2009 Share Posted August 28, 2009 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 Quote Link to comment Share on other sites More sharing options...
ryanwood4 Posted August 28, 2009 Author Share Posted August 28, 2009 // 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 Quote Link to comment Share on other sites More sharing options...
ReKoNiZe Posted August 28, 2009 Share Posted August 28, 2009 You need to fix $memberQuery = SELECT member_id FROM member_id WHERE email='$email'. That was just an example, its fairly close to what you need, look at the INSERT INTO query code right above it and follow that standard. Quote Link to comment Share on other sites More sharing options...
ryanwood4 Posted August 28, 2009 Author Share Posted August 28, 2009 I really don't get what I need to change. I added some spaces between: WHERE email = '$email' which cured the error, but the email still doesn't show the member_id 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.