gum1982 Posted November 13, 2009 Share Posted November 13, 2009 Can someone please tell me why my session wont work. It will catch every other variable from my form fine except the email. page 1 session_start(); $email = $email; $_SESSION['name'] = $first; $_SESSION['email'] = $email; $_SESSION['telephone'] = $telephone; session_write_close(); header('location: http://www.page2.php'); <form id="mot" class="formular" action="" method="post"> <h2>Free Business MOT Sign-up</h2> <fieldset> <legend>Your Details</legend> <label> First name <input value="<?php echo $_POST['name']; ?>" type="text" name="name" class="validate[required,custom[onlyLetter],length[0,100]]" id="name" /> </label> <label> Email address : <input value="<?php echo $_POST['email']; ?>" type="text" class="validate[required,custom[email]] text-input" name="email" id="email" /> </label> <label> Telephone : <input value="<?php echo $_POST['telephone']; ?>" type="text" class="validate[required,custom[telephone]] text-input" name="telephone" id="telephone" /> </label> <label> <span class="checkbox">I am happy to recieve mail : </span> <input type="checkbox" name="check" checked="checked" value="1" <?php if(isset($_POST['check']) == 1) { echo 'unchecked="unchecked"'; } ?> /> </label> <input class="submit" type="submit" name="submit" value="Sign Up"/> </fieldset> </form> Page 2 <?php session_start(); print $_SESSION['name']; print $_SESSION['email']; print $_SESSION['telephone']; ?> It prints out the name and telephone fine but not the email. Any help please? Quote Link to comment https://forums.phpfreaks.com/topic/181389-session-wont-send-email/ Share on other sites More sharing options...
rlelek Posted November 13, 2009 Share Posted November 13, 2009 Hello, Two guesses... #1 - You are reassigning the variable to something that is undefined (aka, blank). right here -> $email = $email; $_SESSION['name'] = $first; $_SESSION['email'] = $email; $_SESSION['telephone'] = $telephone; if $email is not defined (and i don't see that it is), then you will be assigning it no value. #2 - How are you getting from $_POST['email'] to $email? I never saw a statement like $email = $_POST['email']; Ryan Quote Link to comment https://forums.phpfreaks.com/topic/181389-session-wont-send-email/#findComment-956900 Share on other sites More sharing options...
cags Posted November 13, 2009 Share Posted November 13, 2009 The script relies on register_globals being enabled on the server (which is not really a good idea), I've not really experimented with them turned on but it may be possible the $email = $email part would blank the value somehow. I can't really see how though since it should just assign itself to itself. Quote Link to comment https://forums.phpfreaks.com/topic/181389-session-wont-send-email/#findComment-956905 Share on other sites More sharing options...
gum1982 Posted November 13, 2009 Author Share Posted November 13, 2009 Hi thanks for the reply sorry that $email = $email; shoudnt be their. This is just a section off my code ive setup a header redirect and didnt realise that you lose all your variable's when you do this, so im trying to find a way to pass over these varables to the next page. name email telephone I figured the best way to do this is with a session i have never used a session's before and im really new to php. Am i doing this completely wrong, what would you suggest? Any help please cheers Quote Link to comment https://forums.phpfreaks.com/topic/181389-session-wont-send-email/#findComment-956907 Share on other sites More sharing options...
cags Posted November 13, 2009 Share Posted November 13, 2009 The standard way of doing it shouldn't require sessions at all. If you simply put the action of the form to page2.php, it should POST the values to page2.php. Quote Link to comment https://forums.phpfreaks.com/topic/181389-session-wont-send-email/#findComment-956908 Share on other sites More sharing options...
gum1982 Posted November 13, 2009 Author Share Posted November 13, 2009 Hi Cags The only problem ive got with that is i have done all my php validation at the top of this page so it runs the validation then redirects. if(isset($_POST['submit'])){ if(trim($_POST[name]) == '') { //$error = "Please enter your name!"; } elseif(trim($_POST[email])==''){ //$error = "An email address is required!"; } elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST[email])) { //$error = "The e-mail you entered was not in the proper format!"; } elseif(!isset($_POST['check'])) { //$error = "Would you like to tick the box so we can send you the MOT?"; } elseif (add_to_GetResponse($name, $email, null/*custom*/) === false) { // Debug error - you can decide what to do on error if (DEBUG) $error = "Their was an error adding your data"; } else { session_start(); $_SESSION['name'] = $first; $_SESSION['email'] = $email; $_SESSION['telephone'] = $telephone; session_write_close(); header('location: http://www.page2.php'); } Quote Link to comment https://forums.phpfreaks.com/topic/181389-session-wont-send-email/#findComment-956911 Share on other sites More sharing options...
cags Posted November 13, 2009 Share Posted November 13, 2009 Ok, so there is more code, that makes a world of difference. There are a few things I'd recommend changing with your code, but I'll ignore that for now. Since you are using the $_POST array in your validation does that mean you don't rely on register_globals? Do you at some point have lines of code stating... $firstname = $_POST['firstname']; $email = $_POST['email']; ... // etc Quote Link to comment https://forums.phpfreaks.com/topic/181389-session-wont-send-email/#findComment-956917 Share on other sites More sharing options...
gum1982 Posted November 13, 2009 Author Share Posted November 13, 2009 Hi Cags Yeah this is my full code. I do have those two lines is this causing the problem? <?php include_once("lib/get-response.php"); define('DEBUG', true); // change this to true to control debug output, or false function add_to_GetResponse($name, $email, $custom) { // key data $api_key = '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'; $campaign = '!!!!!!!!!!!!!!!!!!'; $ref = "000"; // optional, may be null $ip = $_SERVER['REMOTE_ADDR'];//"123.123.123.123"; // optional, may be null // add to GetResponse addSubscriberGET($api_key, $campaign, $email, $name, $ref, $ip, $custom); } $first = htmlspecialchars($_POST['name']); $email = htmlspecialchars($_POST['email']); if(isset($_POST['submit'])){ if(trim($_POST[name]) == '') { //$error = "Please enter your name!"; } elseif(trim($_POST[email])==''){ //$error = "An email address is required!"; } elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST[email])) { //$error = "The e-mail you entered was not in the proper format!"; } elseif(!isset($_POST['check'])) { //$error = "Would you like to tick the box so we can send you the MOT?"; } elseif (add_to_GetResponse($name, $email, null/*custom*/) === false) { // Debug error - you can decide what to do on error if (DEBUG) $error = "Their was an error adding your data"; } else { session_start(); $_SESSION['name'] = $first; $_SESSION['email'] = $email; $_SESSION['telephone'] = $telephone; session_write_close(); header('location: http://www.page2.php'); } } ?> <html> <form id="mot" class="formular" action="" method="post"> <h2>Free Business MOT Sign-up</h2> <?php //echo "<span style=color:red>$error</span>"; ?> <fieldset> <legend>Your Details</legend> <label> First name <input value="<?php echo $_POST['name']; ?>" type="text" name="name" id="name" /> </label> <label> Email address : <input value="<?php echo $_POST['email']; ?>" type="text" name="email" id="email" /> </label> <label> Telephone : <input value="<?php echo $_POST['telephone']; ?>" type="text" name="telephone" id="telephone" /> </label> <label> <span class="checkbox">I am happy to recieve mail : </span> <input type="checkbox" id="agree" name="agree" value="1" <?php if(isset($_POST['check']) == 1) { echo 'unchecked="unchecked"'; } ?> /> </label> <input class="submit" type="submit" name="submit" value="Sign Up"/> </fieldset> </form> </html Quote Link to comment https://forums.phpfreaks.com/topic/181389-session-wont-send-email/#findComment-956924 Share on other sites More sharing options...
cags Posted November 13, 2009 Share Posted November 13, 2009 I don't see how your code can ever reach the else block. elseif(!isset($_POST['check'])) { That line says... If there isn't a key of 'check' in the $_POST array, which there won't be because you don't have an HTML input with that name. Also add_to_GetResponse doesn't return anything, which means it will always be === false. Quote Link to comment https://forums.phpfreaks.com/topic/181389-session-wont-send-email/#findComment-956935 Share on other sites More sharing options...
chauffeur Posted November 13, 2009 Share Posted November 13, 2009 Email Probs? Look up the posts by chauffeur. I put up a complete working scrip in the last 2 weeks. Search things out before asking the 'same old' again and again please. Quote Link to comment https://forums.phpfreaks.com/topic/181389-session-wont-send-email/#findComment-957025 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.