Page shows up blank

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ppc
Forum Newbie
Posts: 14
Joined: Sat May 27, 2006 9:59 pm

Page shows up blank

Post 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
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post 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.
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post 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 '.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
ppc
Forum Newbie
Posts: 14
Joined: Sat May 27, 2006 9:59 pm

Post 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.
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

What is your PHP version? (make sure your PHP version is > 4.1, when the $_POST superglobal was introduced. )
ppc
Forum Newbie
Posts: 14
Joined: Sat May 27, 2006 9:59 pm

Post by ppc »

I have PHP Version 4.4.2
Post Reply