What is the cause of these errors | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the cause of these errors

I',m trying to make a registration system here's the webpage displaying the error : https://naijalife.000webhostapp.com/good.php And the code : https://code.sololearn.com/ww724T97Rsz2/?ref=app

4th Nov 2020, 6:22 AM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
2 Answers
+ 3
FIX 1: $username is undefined when not isset($_POST['username']). You probably want the $sql calculation in that if-statement so it doesn't get hit when $_POST['username'] isn't set. Moving the $sql calculation should fix the "Undefined variable: username" error. FIX 2: Also, I think you should also change $con to $mysqli in this line: $con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME); Renaming $con to $mysqli should fix some of the "Undefined variable: mysqli" messages. There are other error messages but you should fix those 2 first. After that gets working without any errors, you should look into prepared statements. real_escape_string and your escaping efforts will be simpler and more secure with prepared statements.
4th Nov 2020, 7:07 AM
Josh Greig
Josh Greig - avatar
+ 2
Start with adjust: 1) You use $mysli as var but your connection is referenced by $con var then you have to use it 2) $username is setted only if request type is post and contains an username parameter but you use it anyway and its bad 3) you dont check myslqli codes for errors
4th Nov 2020, 7:10 AM
KrOW
KrOW - avatar