Please can anybody help,
I have the following script that works on php 4.4.7 but not with 5.2.3.
it gives this error Notice: Undefined variable: submit

<form name="search" method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="Ingredients">Ingredients</option>
<Option VALUE="Category">Category</option>
<Option VALUE="Title">Title</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input name="submit" type="submit" id="submit" value="submit" />
</form>

<?
if ($submit)
{
echo "<h2>Results</h2><p>";

if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
include ('config.inc.php');

$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
$data = mysql_query("SELECT * FROM  $table WHERE upper($field) LIKE'%$find%'");
while($result = mysql_fetch_array( $data ))
{
 extract($result);
   echo"
<table width='780'  border='0' cellspacing='2' cellpadding='0'>


</table>
";}

$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}

echo "<b>Searched For:</b> " .$find;
}
?>

Please can anyone help its eating at my brain

    This time it's about register_globals being off. $submit isn't set - $_POST['submit'] is. The same for other varibles from form.

      As such, you'll need to fix all of your scripts to use the appropriate superglobal arrays. More information about these variables can be found here: [man]variables.predefined[/man].

        2 years later

        I'm running into the same problem, I'm still pretty new to PHP however I can fumble around. I'm reusing a piece of code that worked on a browser exactly like koop had.
        Submitting the form to itself. I've read the articles attached although if i try to replace $submit with $post['submit'] or $GET['submit'] I get an undefined index instead. I'm sure it's something simple I'm missing!

        <form method="post" action="<?php echo $_SERVER['PHP_SELF'].'?id='.$_GET['id']; ?>">
        <table>
        <tr>
        	<td>Issue Id</td>
        	<td><?php echo $row['id'];?></td>
        </tr>
        <tr>
        	<td>Issue Tech</td>
        	<td><?php echo $row['tech'];?></td>
        </tr>
        <tr>
        	<td>Issue Date</td>
        	<td><?php echo $row['date'];?></td>
        </tr>
        <tr>
        	<td>Issue Description</td>
        	<td><textarea name=issue rows=5 cols=30 name=issue><?php echo $row['issue'];?></textarea></td>
        </tr>
        <tr>
        	<td>Issue Resolution</td>
        	<td><textarea name=resolve rows=5 cols=30 name=resolve></textarea></td>
        </tr>
        <tr>
        	<td>Status</td>
        	<td>
        		<select name="status">
        		<option value="open">open</option>
        		<option value="closed">closed</option>
        		</select>
        	</td>
        </tr>
        <tr>
        	<td>Computer Name</td>
        	<td><?php echo $row['comp'];?></td>
        </tr>
        </table>
        <input type="Submit" value="Submit Issue Change" name="submit">
        
        
        
        <?php
        
        if ($submit) {
        
          // process form
        
        /* Build SQL Connection. */
        $serverName = "asdfa";
        $myUser = "adsfar";
        $myPass = "adsf";
        $connectionOptions = array( "UID"=>$myUser,
        	"PWD"=>$myPass,
        	"Database"=>"tracking");
        /* Connect using Windows Authentication. */
        
        $conn = sqlsrv_connect( $serverName, $connectionOptions);
        
        if (!$conn)
          {
          die('Could not connect: ' . sqlsrv_error());
          }
        
        
        $sql = "UPDATE issueList SET issue='$issue', resolution='$resolve', status='$status' WHERE id=".$_GET['id'];
        
         $result = sqlsrv_query($sql,$conn);
        
          echo sqlsrv_error();
        
          echo "Contact information has been updated!\n";
        }
          ?>
          mpeveley;10947191 wrote:

          if i try to replace $submit with $post['submit']

          $post isn't one of the predefined superglobal arrays; $_POST is.

          For more information about these superglobal arrays, see these two manual pages: [man]variables.external[/man] and [man]reserved.variables[/man].

            Sorry I forgot to cap it in my post however I've tried
            If ($_POST['submit']) {

            Yet I still get the undefined index error? it's boggling my mind!

              I gave up and ended up just posting to a separate page. Thanks tho!

                You'll get the undefined index if the item doesn't exist yet. You should never access external data without first verifying that it exists. As such, you'll see your if() statement written more properly as:

                if(isset($_POST['submit'])) {

                or:

                if(!empty($_POST['submit'])) {
                  Write a Reply...