0

Help solve the following error in my signup.php file

<?php if(count(errors) > 0): ?> <div class="alert alert-danger"> <?php foreach($errors as $error): ?> <li><?php echo $error; ?></li> <?php endforeach; ?> </div> <?php endif; ?> <?php if(count(errors) > 0): ?> THIS IS THE LINE WITH THE ERROR These two errors are evident on my registration form Warning: Use of undefined constant errors - assumed 'errors' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\USER-VERIFICATION\signup.php Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\USER-VERIFICATION\signup.php on this line Kindly help

29th Feb 2020, 8:42 PM
evans
12 Respuestas
+ 1
Hello Evans, Variables in PHP are written with $ prefix, and <errors> on that line is missing that symbol. So PHP thought you passed a constant, instead of a variable (an array to be specific). Try to change `errors` to `$errors` and run the code again.
29th Feb 2020, 9:06 PM
Ipang
+ 1
Thanks Ipang I appreciate your kind support. It really worked but I have another error in the following: if ($password !== $passwordConf) { $errors['password'] = "The two password do not match"; } if ($password !== $passwordConf) ON THIS LINE!! It shows the two errors below Notice: Undefined variable: password in C:\xampp\htdocs\USER-VERIFICATION\controllers\authController.php Notice: Undefined variable: passwordConf in C:\xampp\htdocs\USER-VERIFICATION\controllers\authController.php
1st Mar 2020, 6:53 AM
evans
+ 1
simply put?? My intention is to compare password and password confirm so that if they don,t match an error msg "passwords do not match "is shown to the user as they try to register. This is //validation. // validation if (empty($username)) { $errors['username'] = "Username required"; } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors['email'] = "Email address is invalid"; } if (empty($email)) { $errors['email'] = "Email required"; } if (empty($password)) { $errors['password'] = "Password required"; } if ($password !== $passwordConf) { $errors['password'] = "The two password do not match"; }
1st Mar 2020, 2:42 PM
evans
+ 1
Simply put = in simple way (Edit) Evans, I understand your intention by comparing $password to $passwordConf. But the problem here is, PHP doesn't recognize $password or $passwordConf. So I suggest you to track your code, where $password and $passwordConf are initialized. Start searching for $password and $passwordConf from beginning of validation code block upwards. It will be better if you can save a copy of that troubling file in SoloLearn and share the code link. Partial code like this doesn't help much trying to isolate the problem.
1st Mar 2020, 2:45 PM
Ipang
+ 1
ok let me share to you the link https://code.sololearn.com/w58SM1kGX7f9 for the authController.php https://code.sololearn.com/wYIQW9plcHIM for the signup.php
1st Mar 2020, 4:22 PM
evans
+ 1
Thanks for the changes I'll send you the rectified code once I have made the changes.
2nd Mar 2020, 7:44 AM
evans
+ 1
I really appreciate your kind support, It has finally worked. Thanks a lot Ipang. I really feel so humbled for your support
2nd Mar 2020, 7:03 PM
evans
0
Evans, The warning message clearly stated that neither <$password> nor <$passwordConf> was defined. Solution is to make sure those variables are properly initiaialized.
1st Mar 2020, 9:22 AM
Ipang
0
how do you initialize them properly please??
1st Mar 2020, 11:46 AM
evans
0
Variable initialization means you assign a value for the variable. The warning for <$password> and <$passwordConf> came because PHP don't see any such variable. Next thing it sees is that you try to use those variable names in a comparison (using `if` statement). You can't compare things that do not exist, simply put.
1st Mar 2020, 12:31 PM
Ipang
0
Evans, Have you solved the problem yet buddy? I have read your codes. Thanks for elaborating with the codes, it helps to understand better where the problem lies by now 👍 Analysis: * FILE: signup.php It might be okay to remove line 1 and line 55. Unnecessary PHP code block start at line 1, and block end at line 55. * FILE: authController.php Line 10-14: Variables have underscore in their names ($_username, $_email, $_password, $_passwordConf). The validation block (Line 16-30) checks for and uses different variable names (that do not exist - uninitialized) Line 35: Second argument for `bind_param` refers to $email. It should refer to $_email. Line 45: $password does not exist. Use $_password instead Line 51: Some arguments for `bind_param` refer to non existing variable names => $username, $email, $password. Line 57: Use of non existing variable $username. Line 58: Use of non existing variable $email. P.S. Use consistent style for variable naming convention 👍
2nd Mar 2020, 5:47 AM
Ipang
0
No problem Evans, I'm glad if it helps 👌
3rd Mar 2020, 1:37 AM
Ipang