PHP undefined key and variable

0 votes
I followed your tutorial here about user registration using PHP and MySQL here: https://youtu.be/qjwc8ScTHnY

However, Im getting these errors:

Warning: Undefined array key "username" in C:\xampp\htdocs\Sublime\Web1\server.php on line 17

Warning: Undefined array key "email" in C:\xampp\htdocs\Sublime\Web1\server.php on line 18

Warning: Undefined array key "password" in C:\xampp\htdocs\Sublime\Web1\server.php on line 19

Warning: Undefined array key "confirmpassword" in C:\xampp\htdocs\Sublime\Web1\server.php on line 20


This are those line:

$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password = mysqli_real_escape_string($db, $_POST['password']);
$confirmpassword = mysqli_real_escape_string($db, $_POST['confirmpassword']);

I did a work around by doing this:

if (isset($_POST['username']) || isset($_POST['email']) || isset($_POST['password']) || isset($_POST['confirmpassword'])) {

    $username = mysqli_real_escape_string($db, $_POST['username']);
    $email = mysqli_real_escape_string($db, $_POST['email']);
    $password = mysqli_real_escape_string($db, $_POST['password']);
    $confirmpassword = mysqli_real_escape_string($db, $_POST['confirmpassword']);
}

But now Im getting undefined variable at line 30 which are $password and $confirmpassword which is the line:

if ($password != $confirmpassword) {array_push($errors, "Password must be the same");};

Please help! And why am I getting these errors? Thanks!
Dec 29, 2020 in PHP by Dann carlo
• 120 points
2,828 views

1 answer to this question.

0 votes

Hi, @Dann,

If you are using some variable then please check if its set or not

<?=$user_name;?> you need to chnage to <?=(isset($user_name)?$user_name:""?> and same for ot
answered Dec 29, 2020 by anonymous
• 65,870 points

Related Questions In PHP

0 votes
1 answer

Error:“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

Hello @kartik, The best way for getting input string is: $value ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,580 points
13,675 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,580 points
298 views
0 votes
1 answer

How to validate E-mail and URL of Php form?

hey, The code below shows a simple way ...READ MORE

answered Feb 13, 2020 in PHP by manish
458 views
0 votes
1 answer

Complete PHP form with proper validation and syntax

Hey @kartik, It's quite simple to have php ...READ MORE

answered Feb 19, 2020 in PHP by Niroj
• 82,580 points
214 views
0 votes
1 answer

What is type casting and type juggling in php?

Hey, The way by which PHP can assign ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,580 points
927 views
0 votes
1 answer

What is the use of $_REQUEST variable in php?

Hii @kartik, The $_REQUEST variable is used to read the ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,580 points
221 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
1,987 views
0 votes
1 answer

Vertically centering text in a div

Try this code: .smallUnitBox { ...READ MORE

answered Sep 3, 2018 in Blockchain by digger
• 26,700 points
120 views
0 votes
1 answer
0 votes
0 answers

Anyone can help me out to understand the semantic of (document.getElementBYId("demo").innerHTML="Hello") ?

Hello guys, Can Someone helps me to find ...READ MORE

Jan 17, 2020 in Web Development by anonymous
• 37,490 points
154 views