Jump to content

Form Echo Problem


xtoyduck

Recommended Posts

Having problems with my script echo without form being completed yet. Any help would be appreciated.

 

The echo that is outputting early is "You must enter a Session Name".

 

<html>
   <head>
      <title>ReH-0.1--Create a Session</title>
   </head>
   <body bgcolor="575757">
     <center>
<?php
   
   $error = "Could not connect to the database";
   mysql_connect('localhost','root','') or die ($error);
   mysql_select_db('temp') or die ($error);
   
   //Set Variables
   $id = $_POST['id'];
   $table = $POST['table'];
   
   //Check for exsistence
   if (!$id or !$table)
     {
      echo "<font color='#ff0000'>You must enter a Session Name</font>";
     } else {
      echo "Congrats!";
     }

?>
         <h2 style="color:#fff">ReH-0.1 Password Encryption</h2><br><br>
         <font color="#fff">Before encrypting your password, a session must be started. We need you to enter a personal session name that you will remember so that you password is protected by this session.</font><br><br>
         <form action="session_start.php" method="POST">
            <label for="id" style="color: #fff;">Session Name:
            <input type="text" maxlength="10" size="10" name="id"></label><br><br>
            <label for="table" style="color: #fff;">Session Name Confirmation:
            <input type="text" maxlength="10" size="10" name="table"></label><br><br>
            <input type="submit" value="Create Session">
         </form>
      </center>
   </body>
</html>

Link to comment
Share on other sites

You are saying that there is no form yet. Which means the post variables will be NULL or false.

Then your if statements simply checks if either of them is false, which they are. Meaning it will output "You must enter a Session name"

 

I do not see a problem here really?

 

Also, this kind of code should normally be placed in in a seperate file, next to your index.php file.. then the form will direct you towards this file, and in this seperate file, if you use $_POST['id'] you will get the form's "id" field.

 

So.. any more questions?

Link to comment
Share on other sites

Okay it fixed my problem, but caused another :(  Now I can't even get my echo to pop up. It just takes me to my "session_start.php" page without leaving the error echo.

 

Here's the code:

 

<html>
   <head>
      <title>ReH-0.1--Create a Session</title>
   </head>
   <body bgcolor="575757">
     <center>
<?php
   
   $error = "Could not connect to the database";
   mysql_connect('localhost','root','') or die ($error);
   mysql_select_db('temp') or die ($error);
   
   if ($_SERVER['REQUEST_METHOD'] == "POST")
     {
      //Set Variables
      $id = $_POST['id']; 
      $table = $_POST['table'];
      
      //Check for existense
      if (!$id or !$table)
          {
           echo "You must enter a session name to continue";
          } else {
           echo "Thank You!";
          }
     } else {
     echo "Sorry, but the request to grab data has failed";
?>
         <h2 style="color:#fff">ReH-0.1 Password Encryption</h2><br><br>
         <font color="#fff">Before encrypting your password, a session must be started. We need you to enter a personal session name that you will remember so that you password is protected by this session.</font><br><br>
         <form action="session_start.php" method="POST">
            <label for="id" style="color: #fff;">Session Name:
            <input type="text" maxlength="10" size="10" name="id"></label><br><br>
            <label for="table" style="color: #fff;">Session Name Confirmation:
            <input type="text" maxlength="10" size="10" name="table"></label><br><br>
            <input type="submit" value="Create Session">
         </form>
      </center>
   </body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.