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
https://forums.phpfreaks.com/topic/227638-undefined-variable-submit/
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.

*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.,

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.