+ 2

How do i fix this

I want to know how to fix this error on this page : https://naijalife.000webhostapp.com/good.php I used this code : https://code.sololearn.com/ww724T97Rsz2/?ref=app

7th Nov 2020, 8:24 AM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
13 Answers
+ 3
Joseph, <$result> is a mysqli_result instance (an object in short), so we can't just go and concatenate strings with it. Try to change line 24 to not to mix <$result> with string for output. echo "Error in query:<br>".$mysqli->error;
7th Nov 2020, 1:49 PM
Ipang
+ 2
you just posted database credentials online. I would quickly change them if your db is accessible by the internet
7th Nov 2020, 9:14 AM
John Doe
+ 2
well the script doesn‘t output anything, and if i go to your page I indeed only see a white page
7th Nov 2020, 11:49 AM
John Doe
+ 2
Joseph, Can you tell what error message you got when running that code on your side? without this information, it is rather hard to isolate the problem.
7th Nov 2020, 12:56 PM
Ipang
+ 2
Thanks
7th Nov 2020, 1:57 PM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
+ 2
Not a problem 👌 Did it work though Joseph?
7th Nov 2020, 1:59 PM
Ipang
+ 2
the if else statement on line 20 and 23 doesn‘t make much sense. The if statement checks if the username already exists, so far so good. However, if it doesn‘t exist it proceeds to print the error message that there is an error in the query?? why? Can‘t you get rid of the else statement?
7th Nov 2020, 2:08 PM
John Doe
+ 2
Also you don‘t need to fetch the last id in the table. you can set the id column to primary and autoincrement and then just leave the id out of the INSERT statement.
7th Nov 2020, 2:11 PM
John Doe
+ 1
So do know what's wrong
7th Nov 2020, 9:21 AM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
+ 1
It was something like, fatal error: uncaught object of class mysqli_result not converted to string on line 24
7th Nov 2020, 1:42 PM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
+ 1
Be aware to read up on something called sql injection and prepared statements in the future. if someone would have their username as "; DELETE FROM accounts; — They could for instance delete your whole accounts table
7th Nov 2020, 2:16 PM
John Doe
+ 1
never mind, I see you‘re using real_escape_string. That also works
7th Nov 2020, 2:18 PM
John Doe
8th Nov 2020, 2:03 PM
Katya Lanubirt
Katya Lanubirt - avatar