Kev0121 Posted December 15, 2008 Share Posted December 15, 2008 Well basically heres my error Notice: Undefined index: submit in C:\wamp\www\Website\register.php_phpd_tmp14.php on line 5 and heres my code i have no idea whats wrong with it <?php include "functions.php"; connect(); if(!$_POST['submit']) { echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form method=\"post\" action=\"register.php\">\n"; echo "<tr><td colspan=\"2\" align=\"center\">Registration Form</td></tr>\n"; echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"></td></tr>\n"; echo "<tr><td>Password</td><td><input type=\"password\" name=\"password\"></td></tr>\n"; echo "<tr><td>Confirm</td><td><input type=\"password\" name=\"passconf\"></td></tr>\n"; echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Register\"></td></tr>\n"; echo "</form></table>\n"; } else { $user = protect($_POST['username']); $pass = protect($_POST['password']); $confirm = protect($_POST['passconf']); } ?> Link to comment https://forums.phpfreaks.com/topic/137045-solved-undefined-error-again-lol/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 15, 2008 Share Posted December 15, 2008 Use isset() - if(!isset($_POST['submit'])) In your existing code, the variable is evaluated, which generates an error if it does not exist. Using isset() tests if the variable exists without evaluating the variable. Link to comment https://forums.phpfreaks.com/topic/137045-solved-undefined-error-again-lol/#findComment-715759 Share on other sites More sharing options...
Mad Mick Posted December 15, 2008 Share Posted December 15, 2008 It means there is no submit element of $_POST. You should add the PHP if (!array_key_exists('submit',$_POST)) {//do something} else {//handle error} to make your code more robust and handle this type of possibility. You can combine it with the if statement you currently use. It is only a Notice (not a Warning or Error) which you can turn off - but its always better to solve the problem than fiddle it! Link to comment https://forums.phpfreaks.com/topic/137045-solved-undefined-error-again-lol/#findComment-715764 Share on other sites More sharing options...
Kev0121 Posted December 15, 2008 Author Share Posted December 15, 2008 Thanks alot it worked How would i turn it off btw ? Link to comment https://forums.phpfreaks.com/topic/137045-solved-undefined-error-again-lol/#findComment-715784 Share on other sites More sharing options...
PFMaBiSmAd Posted December 15, 2008 Share Posted December 15, 2008 Don't turn off Notice messages. Doing so will prevent the logging of things like hackers probing your script by sending it unexpected data in an attempt to break into your site. http://www.phpfreaks.com/forums/index.php/topic,229515.msg1062117.html#msg1062117 Link to comment https://forums.phpfreaks.com/topic/137045-solved-undefined-error-again-lol/#findComment-715790 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.