Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

All-In-One Form, should I be using sessions here?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

All-In-One Form, should I be using sessions here?

Postby madcat » Wed Feb 26, 2003 12:09 pm

Hi All-

Here is my problem. I have an All-In-One-Form that consists of a login area for username/password and an HTML form that processes the form info and sends it off in an email. Both the login form and HTML form are in their own variables ($login, $the_form) respectively, and are outputted at arbitrary points in the script.

So far, everything is correct except for when the user tries to submit the form.

So the login screen pops-up, and the username and password are entered. A mysql database table checks the validity of the items-if valid, the form displays. If not, show the login. No problem.

But each time the user hits submit on the main HTML form, the login form pops back up because it gets stuck on one of the previous conditions within the script. I need a way that I can show that once at the HTML form, they no longer need to enter their username/password. Can I do this with sessions even when this is just one script that reloads itself? What are some ways I could approach this?

- hope it makes sense to you.

Thanks for any suggestions!
madcat
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Sep 20, 2002 9:06 am

Postby bmcua » Wed Feb 26, 2003 4:09 pm

any code i can see???
bmcua
 

Postby madcat » Wed Feb 26, 2003 6:28 pm

This is somewhat long, but why not give you the whole picture. I appreciate any help, I'm quite lost- but yet so close!

Code: Select all
<html>
<head>
   <title>Communication : Support Form</title>
</head>

<body>

<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
   <tr>
      <td id="banner" colspan="2" height="63"><br /></td>
   </tr>
   <tr>
      <td id="nav" width="20%" valign="top"><br /></td>
      <td valign="top" width="80%">
      
      <?php
      
      $login = "
         Login Form...
                               ";
         
      $the_form = "
                             Main HTML Form...   
                                    ";
      
            if (!$_POST[check_login]) {
               echo "$login";
               exit;
            } else if ($_POST[check_login]) {
               if ((!$_POST[username]) && (!$_POST[password])) {
                  $up_passed = "true";
                  echo "<p class='error'>Please enter your username and password!</p>";
                  echo "$login";
               } else {   
               $dbname = "token";
               $table = "truck";
               $connection = @mysql_connect("localhost", "rick", "wire") or die(mysql_error());
               $db = @mysql_select_db($dbname, $connection) or die(mysql_error());
               $sql = "SELECT id FROM $table WHERE username = '".$_POST['username']."' AND    
               password = '".$_POST['password']."'";
               $result = @mysql_query($sql, $connection) or die(mysql_error());
               if (mysql_num_rows($result) != 1) {
                  echo "<p class='error'>Incorrect login, please enter your username and password.</p>";
                  echo "$login";
               } else if(mysql_num_rows($result) == 1) {
               if (!$_POST[check]) {
               echo "$the_form";
            } else if ($_POST['check']) {
            
            if (!$_POST[fname]) {
            $fname_error = "<p class='error'>Please enter your first name.</p><br />";
            $transmission = "stop";
            }

            if (!$_POST[lname]) {
               $lname_error = "<p class='error'>Please enter your last name.</p><br />";
               $transmission = "stop";
            }

            if (!$_POST[email]) {
               $email_error = "<p class='error'>Please enter your email address.</p><br />";
               $transmission = "stop";
            }
            
            if ($transmission != "stop") {
               $recipients = "Communication@bogushelp.net";
               $subject = "PMT Communication Ticket";
               $mailheaders = "From: bogushelp.net <> \n";
               $mailheaders .= "Reply-To: $_POST[email]\n\n";
   
               $contents = "CONTENTS OF Communication TICKET\n";
               $contents .= "First Name: $_POST[fname]\n";
               $contents .= "Last Name:  $_POST[lname]\n";
               $contents .= "Email:       $_POST[email]\n";
               $contents .= "Phone:       $_POST[phone]\n";
               $contents .= "Position:$_POST[level]\n";
               $contents .= "Location:$_POST[location]\n";
               $contents .= "Hardware Problem:   $_POST[hardwareProblem]\n";
               $contents .= "Software Problem:   $_POST[softwareProblem]\n";
               $contents .= "Network Problem:   $_POST[networkProblem]\n";
               $contents .= "Other Problem:   $_POST[problemNotSpecified]\n";
               $contents .= "Internet Connection: $_POST[internetConnect]\n";
               $contents .= "Email Transmission:  $_POST[sendReceiveEmail]\n";
               $contents .= "Computer Printing:   $_POST[cpuPrint]\n";
               $contents .= "Problem Description: " . stripslashes($_POST[description]);
   
               mail($recipients, $subject, $contents, $mailheaders);
               echo "<div class='error-correction'>";
               echo "<p>Thank you.  Your message has been sent to our technicians.  We will be with    you shortly.</p>";
               echo "<a class='error-anchor' href='index.html'>Main Page</a> | ";
               echo "<a class='error-anchor' href='http://www.bogussite.com/'>Pill Mills and Thrills</a>";
               echo "</div>";
               }
   
               else if ($transmission == "stop") {
                  echo "<h2>Form Error Notification</h2>";
                  echo "<p class='error'>$fname_error</p>";
                  echo "<p class='error'>$lname_error</p>";
                  echo "<p class='error'>$email_error</p>";
                  echo "$the_form";
               }
                      
               }
            }
         }
      }
         
         ?>
   
      </td>
   </tr>
</table>

</body>
</html>
madcat
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Sep 20, 2002 9:06 am

Postby Romantik » Thu Feb 27, 2003 12:29 am

Hi!
Use sessions
and save in sessions UserID and check it in your forms
session_start();
if(!isset($_SESSION["UserID"]))
exit;
else
$sql= "SELECT * ..... WHERE... AND id=".$_SESSION["UserID"];
Romantik
New php-forum User
New php-forum User
 
Posts: 67
Joined: Mon Feb 24, 2003 2:55 am
Location: ../Ukraine/Kherson


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.