Jump to content

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/181389-session-wont-send-email/
Share on other sites

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

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.

 

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

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');

}

 

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

 

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

 

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.

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.