TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-24-2007, 05:11 AM   #1 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default Values being returned as NULL

I'm not sure what's causing it, I'm using a bit of the code from when you guys helped me last which seemed work work, but now it's not.

http://phpfi.com/271062

For the elseif section to see if any variables are empty, would that be best to put into one if condition and use the || operator?

Also, I have another question. Is all that in the __construct() function necessary? It doesn't seem like it, but I'm not sure how else to pass the variables off into member variables.
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Old 10-24-2007, 10:00 AM   #2 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Hi Andrew,

The class looks fine to me. Setting default values in the constructor is a good thing, it provides a consistent place for property initialisation. With that said, if not all properties need to be set via the construct call then I would suggest adding a few "settor" methods, for example, to set the title independently of the constructor then you could add this method:

PHP Code:
public function setTitle($szTitle)
{
    
$this->m_szTitle $szTitle;

If you need to access any of these properties outside the class you should also create "gettor" methods to do this, such as:

PHP Code:
public function getTitle()
{
    return 
$this->m_szTitle;

Both the gettor and settor methods are only any use when you make your class properties hidden from outside the scope of the class (private or protected), they allow users to change the values of your properties but only by using the rules that you specify in you settor. I would suggest this change as an improvment.

As for your santize method, this isn't the cleanest approach to validation but it looks OK for its the task it is supposed to do.
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
Old 10-28-2007, 08:20 PM   #3 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default

How would you recommend doing the santize function? Not looking for you to create a full function to do it, but could you list off how you would go about doing it?
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Old 10-29-2007, 10:14 AM   #4 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

I think what Karl is refering too, is that you do not have any clarity in your error reporting:

PHP Code:

        
if (empty($this->m_name) || empty($this->m_email) || empty($this->m_artist) || empty($this->m_album) || 
            empty(
$this->m_release) || empty($this->m_song) || empty($this->m_lyrics)) {
            
$szError .= 'Please fill in all required fields.<br />'."\n";
            
$bError true;
        } 
Errors like "You did not fill in the lyrics column" would be better.

I would hazard a guess that Karl will recommend an external validation class, as would i :)
__________________
Halo 3 Cheats
bluesaga is offline  
Reply With Quote
Old 10-29-2007, 11:55 AM   #5 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Yep bluesaga is right. I would improve the validation to allow for custom error messages, as bluesaga said, an external, reusable class would be ideal for this job.
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
Old 10-30-2007, 12:45 AM   #6 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default

Well, I would like to get it working first, then update later. I'll work on the specified errors for now.

Fixed all the bugs. Just stupid errors like forgetting the m_, capitalizing stuff that shouldn't have been, etc.

Last edited by Andrew : 10-30-2007 at 01:07 AM.
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:37 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design