colleyboy Posted February 14, 2011 Share Posted February 14, 2011 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/227638-undefined-variable-submit/ Share on other sites More sharing options...
Jessica Posted February 14, 2011 Share Posted February 14, 2011 read about $_GLOBALS and how to use $_POST instead. Quote Link to comment https://forums.phpfreaks.com/topic/227638-undefined-variable-submit/#findComment-1174100 Share on other sites More sharing options...
colleyboy Posted February 14, 2011 Author Share Posted February 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/227638-undefined-variable-submit/#findComment-1174115 Share on other sites More sharing options...
Jessica Posted February 14, 2011 Share Posted February 14, 2011 That has nothing to do with what I said. $submit is not defined because you don't define it. You need to check the $_POST array for submit. Again, see my post above. Quote Link to comment https://forums.phpfreaks.com/topic/227638-undefined-variable-submit/#findComment-1174119 Share on other sites More sharing options...
colleyboy Posted February 14, 2011 Author Share Posted February 14, 2011 I have used the post array in the form though: <form method="post" action="<?php echo $PHP_SELF?>"> So how can it be undefined? Sorry... I am fairly new Quote Link to comment https://forums.phpfreaks.com/topic/227638-undefined-variable-submit/#findComment-1174121 Share on other sites More sharing options...
Jessica Posted February 14, 2011 Share Posted February 14, 2011 http://lmgtfy.com/?q=PHP+POST 4th one down is good. Quote Link to comment https://forums.phpfreaks.com/topic/227638-undefined-variable-submit/#findComment-1174124 Share on other sites More sharing options...
colleyboy Posted February 14, 2011 Author Share Posted February 14, 2011 Ok but they all say about the file bieng outside of the one its sent from. I want to send the info to the same file the forms in. Im a bit confused. Any more help available please would be great!? Ian Quote Link to comment https://forums.phpfreaks.com/topic/227638-undefined-variable-submit/#findComment-1174132 Share on other sites More sharing options...
Jessica Posted February 14, 2011 Share Posted February 14, 2011 *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., Quote Link to comment https://forums.phpfreaks.com/topic/227638-undefined-variable-submit/#findComment-1174137 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.