PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Sep 24, 2020 4:11 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Thu Dec 18, 2014 1:10 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
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

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 :

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 :D ..


Thank you .

Gautam .


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 1:50 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada

_________________


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 1:51 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
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.

_________________


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 1:58 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
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
() ()


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 2:01 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
:( :'( ok , but i just want to still do this . jst so i can get a hang of oops . please .


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 2:12 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada

_________________


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 2:38 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
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 :


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 2:48 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
Sometimes. What if $this->results is empty or false?

_________________


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 2:55 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
so what can i do to correct that celauran .

check (is_array($row)) before the foreach loop ???


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 2:56 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
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.

_________________


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 2:59 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
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 .


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 3:04 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada

_________________


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 3:12 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
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 ! :)


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 3:15 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
in te index.php file u'll see the following code :

Syntax: [ Download ] [ Hide ]
<?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 .


Top
 Profile  
 
PostPosted: Thu Dec 18, 2014 3:18 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
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.

_________________


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group