PHP Sessions

Basically I’ve a Contact Form where a user fills in Name, Email Address and Comments and then there is a Submit button. If I just hit “Submit” without filling in anything or wrong information, it takes me to this page, send_form_email.php. This page has all the validators in it. I want it to sort of (I say sort of because I still need to check whether they input everything correctly) bypass this page and go to “submitted-contact.php” page (it’s going to this page but its not showing the following as specified in the 2) where it displays one of the 2 things: 1) Login Success 2) Try Again!

Right now, there’s nothing showing. :expressionless:

send_form_email.php has this at the very top and it calls header location to the page,
submitted-contact.php
[php]

<?php session_start(); $_SESSION['error']=true; $_SESSION['error']=false; ?> <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "Your email subject line here"; function died($error) { // your error code can go here echo $error; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['email']) || !isset($_POST['comments'])) { died(''); } $first_name = $_POST['first_name']; // required $email_from = $_POST['email']; // required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.
'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); $sendit= @mail($email_to, $email_subject, $email_message, $headers); if($sendit){ header('Location:submitted-contact.php'); }else{echo "Email failed to send";} } ?>

[/php]

submitted-contact.php
[php]

CKK Internet Marketing
<div class="navigation">
  <div class="container">
        <a href="#"><img src="images/logo.png"</a>
        <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/about">About Us</a></li>
        <li><a href="/service">Services</a></li>
        <li><a href="/blog">Blog</a></li>
        <li><a href="/index.html#contact">Contact</a></li>
        </ul>
  </div>
 </div>

<div id="submitted-content-2">
  <div class="content container">
<?php if (!isset($_SESSION['flunk'])){ $myString = "MESSAGE FLUNKED!"; echo $myString; }else (!isset($_SESSION['pass'])){ $myString2 = "MESSAGE PASSED!"; ?>
    <div class="clear"></div>
    
  </div>
</div>
</div>
[/php]

The php code in submitted-contact.php, the following code is in the right location but just the wrong syntax?

<?php if (!isset($_SESSION['flunk'])){ $myString = "MESSAGE FLUNKED!"; echo $myString; }else (!isset($_SESSION['pass'])){ $myString2 = "MESSAGE PASSED!"; ?>

Basically, I want to commute from send_form_email.php to submitted-contact.php one of the two things:

  1. If user inputted everything well on the Contact Page, show them, “You’re logged in”
  2. If user inputted wrong information or did not fill in everything on the Contact Page, show them, “Try Again”

I want that to be shown withing my

Sorry, I know this was a long post but I really could use a hand on this. I have been trying to figure this out for the past couple of days! :expressionless:

Thanks guys :slight_smile:
D3158

I don’t know why I cant edit my last post but this is what I meant for this:

The php code in submitted-contact.php, the following code is in the right location but just the wrong syntax?

<?php if (!isset($_SESSION['false'])){ $myString = "MESSAGE FLUNKED!"; echo $myString; }else (!isset($_SESSION['true'])){ $myString2 = "MESSAGE PASSED!"; ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service