Page 1 of 1

Page shows up blank

Posted: Wed May 31, 2006 2:03 pm
by ppc
I can't seem to get this to work. I am trying to get a page to display only if they entered there e-mail address, and for other purposes, I want it to store it in a session (a cookie might also work).

Code: Select all

<?php
session_start();
$email= $_post["email"];
$recipient="test@test.com";
$subject="A survey has been submited";
$msg="E-Mail Address: $email";

if (count($_SESSION['email'])>0){
    print "This is the survey";
}
elseif ($email='')
{
print "Please enter a valid e-mail address to continue: <p>";
print "<form action=\"$SERVER[self_php]\" method=\"post\">
Email: <input name=\"email\" type=\"test\" size=\"20\" maxlength=\"100\"><p>
<input name=\"Submit\" type=\"submit\" value=\"Submit\">";
}

elseif(mail($recipient, $subject, $msg)){

$_SESSION['email'][] = array('email' => $email);
}
?>
Thanx

Posted: Wed May 31, 2006 3:08 pm
by ambivalent
Put this at the start of the script.

Code: Select all

error_reporting(E_ALL);
This:

Code: Select all

if (count($_SESSION['email'])>0){
    print "This is the survey";
}
Should probably be:

Code: Select all

if (isset($_SESSION['email'])){
    print "This is the survey";
}
To test if the session variable is set or not.

Posted: Wed May 31, 2006 3:19 pm
by ok
It's better to write:

Code: Select all

<?php
//...
print '<form action="$SERVER[self_php]" method="post">
Email: <input name="email" type="test" size="20" maxlength="100"><p>
<input name="Submit" type="submit" value="Submit">'; 
//...
?>
Pay attention to the '.

Posted: Wed May 31, 2006 3:59 pm
by Christopher
According to the logic if (count($_SESSION['email']) <= 0) and ($email != '') then you should see nothing -- exactly as programmed.

Note that in the first elseif you have an assignment -- not a logic test -- with ($email='') so $email will always be null and therefore always evaluate to false.

Posted: Sat Jun 03, 2006 9:27 pm
by ppc
I tried "ambivalent" suggestions and got this error:

Notice: Undefined variable: _post in /homepages/htdocs/mysite/test.php on line 4


Arborint, would you mind to show me specifically the changed script that works, i have tried it myself and i cant seem to get it to work, sorry im a begginer at this,




Thanks for everyones help.

Posted: Sun Jun 04, 2006 1:50 am
by ok
What is your PHP version? (make sure your PHP version is > 4.1, when the $_POST superglobal was introduced. )

Posted: Sun Jun 04, 2006 9:57 am
by ppc
I have PHP Version 4.4.2