Jump to content

undefined variable "submit"


colleyboy

Recommended Posts

Have got a form for the user to fill in.  When they press submit the page SHOULD be sent to itself and update the database.

 

When I load the page I keep getting undefined variable "submit" and also when i press button and bottom I get 404 message.

 

<?php
include "variables.php";
?>
<?php

   $date = date("M d, Y");

if ($submit) {

  // process form
$db = mysql_connect($databaseserver, $databaseuser, $databasepass);
        mysql_select_db($databasename,$db);
    
  $sql = "UPDATE $playerstable SET staff = '$staff' WHERE name='$name'";
  $result = mysql_query($sql);

  echo "Thank you! Information entered.<br><a href='$directory/Admin/index.php'>Return to admin panel</a>";

} else{



  // display form



?>

<form method="post" action="<?php echo $PHP_SELF?>">


<center>
    <table border="0" cellpadding="0" width="100%">
      <tr>
        <td width="12%">
        Name:</td>
        <td width="88%"><select size="1" name="name">
<?php
$db = mysql_connect($databaseserver, $databaseuser, $databasepass);
        mysql_select_db($databasename,$db);

$sortby = "name ASC";
$sql="SELECT * FROM $playerstable ORDER BY $sortby";
$result=mysql_query($sql,$db);

$num = mysql_num_rows($result);
$cur = 1;


echo "<ol>";

while ($num >= $cur) {

$row = mysql_fetch_array($result);

$name = $row["name"];

?>
<option><?php echo "$name" ?></option>
<?php

$cur++;
} 

echo "</ol>";

?>
</select></td>
      </tr>
      <tr>
        <td width="12%">
        Staff:</td>
        <td width="88%"><select size="1" name="staff">
  	<option>Yes</option>
        <option>No</option>
  	  </select></td>
      </tr>
    </table>
  </center>

<p>  <input type="Submit" name="submit" value="Enter information">

  </form>

<?php

}

?>

Link to comment
Share on other sites

I understand I can process the form using another method but I wanted to do it by the PHP_SELF method instead.

 

What have I done wrong in the code... cant seem to spot why it is throwing an error at me. 

 

Maybe the if statement is back to front? but i don't know :(

 

Please help.

Link to comment
Share on other sites

*headdesk*

STOP FOCUSING ON THE PHP_SELF FOR A MINUTE. I'm answering THE OTHER QUESTION YOU ASKED.

 

Also, trying to get the page to submit to itself usually causes the programmer to come back later and ask "when I refresh the page it submits the form again!". So I would rethink making the form submit to itself anyway. BUT IGNORE THAT FOR A MINUTE AND READ THE TUTORIALS. You don't read fast enough to have read many pages on that search.,

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.