Jump to content

[SOLVED] Undefined Error Again Lol


Kev0121

Recommended Posts

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

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.

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!

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

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.