Email form

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Sorry beginners question..

The following link is a
test secure login page for our customers.

Type in 123-456-BSE and login, and it returns a form for the customer
to check three typical bits of into, ie refno, name and email. This
works ok and code is below.

//Process login
if (isset($_POST['companyID'])) {
  // Check login
  $companyID = $_POST['companyID'];
  $resultlogin = @mysql_query ("SELECT userID, username, useremail FROM
schott_news WHERE userID='$companyID'");
    while ($row = mysql_fetch_array($resultlogin))
    $userID = $row['userID'];
    $username = $row['username'];
                $useremail = $row['useremail'];
   if ($_POST['companyID'] = $userID)
  $_SESSION['authorized'] = TRUE;
//Process logout
if (isset($_SESSION['authorized'])) {
    //Display secure information
<h1>Please complete all information</h1>
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <input type="text" name="code" value="<?php echo $userID;
?>"/></label><br />
      <label>User Name:
        <input type="text" name="name" value="<?php echo $username;
?>"/></label><br />
      <label>User E-Mail:
        <input type="text" name="email" value="<?php echo $useremail;
      <input type="submit" value="Submit" />
<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>?logout=1">Log
} else {
   //Display login form
<h1>Please Enter Company Ref No</h1>
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>"

      <label>User ID:
        <input type="text" name="companyID" /></label>
      <input type="submit" value="log IN" />

I want to now click on Submit, and the form results are emailed to and the user logged out.

What is the easiest way to achieve this?

Many thanks


Re: Email form

Alec wrote:

Quoted text here. Click to load it


A few pointers:
1) Use the buildfunction mail().
See for details.

2) When you use one script to do everything, you are only making your life  
unneeded difficult. You code will end up with a spaghettilike logictree to  
handle each situation. A situation you should avoid.
Consider changing your action-tag in the form into another script, like  
logout_and_email.php where you handle the logic.
You script shows that you already know how to retrieve information from a  
POST. I suggest you take the logic for emailing to a new script.

3) How to end a session?
This can be done in many ways.
Here is one that empties the session, but keeps the session (id) around for  
future use:
$_SESSION = array();

Read it all here:

Erwin Moller

Quoted text here. Click to load it

Site Timeline