what is this notice referring to

后端 未结 2 692
暖寄归人
暖寄归人 2021-01-24 22:25

Notice: Undefined index: name in C:\\wamp\\www\\espn.com\\registration.php on line 12

Notice: Undefined index: username in C:\\wamp\\www\\espn.com\\registration.php on l

相关标签:
2条回答
  • 2021-01-24 22:36

    It means $_POST['name'], $_POST['username'] and $_POST['password'] do not exist. Your form was most likely not submitted when you accessed registration.php (or the field names are wrong).

    In PHP, you have to make sure every field you will use is set before you use it. You can use !empty or isset function.

    Also, your script is vulnerable to SQL injections, take a look at mysql_real_escape_string function. And your condition is wrong : if you want to know if the username already exists, you should check if it is greater than 0, not 1. You can also use a COUNT(*) query instead of selecting a row.

    0 讨论(0)
  • 2021-01-24 22:40

    Basically the global variables $_POST['name'], $_POST['username'] and $_POST['password'] do not exist. I'd suggest you to check that each input of the form is submitted as a name that can be declared as follows:

    <input name="username"/>
    

    So that you can access the value of that input by $_POST['username']. After that the string that the script output (I'm sorry but the username you specified has already been taken. Please pick another one.) is echoed because your sql query looks like that:

    SELECT username FROM users WHERE username=''
    

    which will return every user with empty ('') username. Also as already suggested please fix the script as soon as possible.

    0 讨论(0)
提交回复
热议问题