Page 1 of 2
debuggng help my simple login system(like 300 lines code)
Posted: Thu Dec 18, 2014 12:10 pm
by gautamz07
guys i really followed this set of tutorials online , its to help me understand the oops concept :
heres the link for one of the videos
https://www.youtube.com/watch?v=uF-L7ympvfw
now i typed out all the code as that guy had done in the video , but i am still getting errors , so i kind of need some help here , for someone to check my code .
i know debugging help is usually not encouraged on forum , but i would really really be grateful and would buy u a beer if you could help me debug this :
heres the link to what i've done on git :
https://github.com/gautamz07/oopslogin
now in mysql you will have to create a table :
with the following attributes :
id fname lname email
and don't forget to change the db name in index.php if you run the code.
now one other difference you need to know if you do this is the guy in the video has used mysqli where as i am using mysql , i know its a crime to be using it , but still for this demo thinggi its ok

..
Thank you .
Gautam .
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 12:50 pm
by Celauran
gautamz07 wrote:but i am still getting errors
Can you be more specific?
gautamz07 wrote:now one other difference you need to know if you do this is the guy in the video has used mysqli where as i am using mysql
Actually,
you're using a mix of both which is responsible for at least some errors.
Because you're using mysql_ functions, you need a call to mysql_select_db
in your connect method.
You're
assigning to $this->$id instead of $this->id. You're also
assuming $row will be an array even though
it could very well be a string.
I have also noticed you're using parentheses in a number of places where you should be using braces (
example).
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 12:51 pm
by Celauran
With the bugs mostly addressed, I feel I should mention that the tutorial video looks to be quite dated. Using var suggests PHP 4, which is ancient. You have methods without visibility, old school require instead of proper autoloading, singletons, etc. It's a bit of a mess.
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 12:58 pm
by gautamz07
Thanks for the pointers ! i'll implement them .
i get the following error .
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\oopslogin\class.table.php on line 27
() ()
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 1:01 pm
by gautamz07

:'( ok , but i just want to still do this . jst so i can get a hang of oops . please .
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 1:12 pm
by Celauran
gautamz07 wrote:Thanks for the pointers ! i'll implement them .
i get the following error .
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\oopslogin\class.table.php on line 27
() ()
Have you fixed all the issues I highlighted? I had it working locally with only those fixes.
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 1:38 pm
by gautamz07
I updated the code celauran ! , for the last pointer , is't the $obj variable , converted to a array on line 48 ??
if ($this->results) {
$obj = mysqli_fetch_assoc($this->results);
}
i mean here :
https://github.com/gautamz07/oopslogin/ ... se.php#L48
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 1:48 pm
by Celauran
Sometimes. What if $this->results is empty or false?
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 1:55 pm
by gautamz07
so what can i do to correct that celauran .
check (is_array($row)) before the foreach loop ???
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 1:56 pm
by Celauran
You could initialize an empty array instead of a string for the default state, or you could check if $row is an array before trying to iterate over it.
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 1:59 pm
by gautamz07
yes ! but that's a logical thing , i'll implement it ! , i still can't get this code to run , i'll post a updated git link .
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 2:04 pm
by Celauran
gautamz07 wrote:i still can't get this code to run
OK, where's it failing now?
gautamz07 wrote:i'll post a updated git link .
That's the nice thing about Git: you don't have to.
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 2:12 pm
by gautamz07
updated ! made the is_array change too .
https://github.com/gautamz07/oopslogin/ ... le.php#L28
celauran , i mean i'll push my changes to git repo !

Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 2:15 pm
by gautamz07
in te index.php file u'll see the following code :
Code: Select all
<?php
include('./class.database.php');
include('./class.table.php');
include('./user.class.php');
$dbo = database::getInstance();
$dbo->connect('localhost', 'root', '' , 'zakoo');
$user = new user();
// $temp = array(1);
$user->load('1');
echo "($user->fname) ($user->lname)";
?>
now i don't get any errors , but the output in the browser i get is :
() ()
i don't know why really .
if you run the code you will know .
Thanks .
Re: debuggng help my simple login system(like 300 lines code
Posted: Thu Dec 18, 2014 2:18 pm
by Celauran
You're still using () instead of {} in a lot of your strings. This leads to bad queries, which are failing silently and reporting no results. Since you're only populating your users' properties if you get results, what you're seeing is expected behaviour.