so this means I have no switch for $Value?
Looking to make a PHP script
So this is the completed Set function?
function Set ($What,$Value) {
//this function sets the value of class variables for the user. All error
//checking to ensure data integrity should be done in here. This function
//should use a switch statement similar to the one in get.
switch ($What){
case 'ID':
$this->ID = $Value;
break;
case 'BillName':
return $this->BillName;
break;
case 'DueWhen':
return $this->DueWhen;
break;
case 'Amount':
return $this->Amount;
break;
case 'error':
return $this->error;
break;
default:
$this->error = "Invalid variable ($What) passed to Set.<br>\n";
return 0;
} //end switch $What
return 0;
} //end Set
sure the you need to check the data and make sure it's valide what happens if I set ID to d and call insert? Error check the data. You'll probably do a bit of regular expressions and some things with functions like is_int
So I have to add this to the function set, I would add it to the case ID, since the other can be intergers right?
So I check if the $what passed from the site is and ID, then I see if the ID is not a numeric value. If it is, I continue with the switch..... right?
Completed Function Set:
function Set ($What,$Value) {
//this function sets the value of class variables for the user. All error
//checking to ensure data integrity should be done in here. This function
//should use a switch statement similar to the one in get.
switch ($What){
case 'ID':
if (!is_numeric($Value)){
$this->error = "Invalid variable ($ID) passed to Set. <br>\n";
} else {
$this->ID = $Value;
break;
} // end If
case 'BillName':
return $this->BillName;
break;
case 'DueWhen':
return $this->DueWhen;
break;
case 'Amount':
return $this->Amount;
break;
case 'error':
return $this->error;
break;
default:
$this->error = "Invalid variable ($What) passed to Set.<br>\n";
return 0;
} //end switch $What
return 0;
} //end Set
you're very close
Originally posted by npereira
function Set ($What,$Value) { switch ($What){ case 'ID': if (!is_numeric($Value)){ $this->error = "Invalid variable ($ID) passed to Set. <br>\n"; return 0; } $this->ID = $Value; break; . . . default: $this->error = "Invalid variable ($What) passed to Set.<br>\n"; return 0; } //end switch $What return 1; } //end Set
Ok, I don't know what to do about this one!
function dbBills() {
//this is the class instantiation function. In here you'll want to create an
//instance of dbAccess and point $this->db at it.
} //end dbTable
Actualy,
I don't know how to setup theses 2 also:
function Search ($wc,$ob='ID',$start=0,$limit=0)
function IDList($start=0,$limit=0)
Or how to start them.
Can you give me a litle crash course on this?
here is what I have dobe up to now.
okay set it right, you should be able to write get as it's like set but even easier.
dbBills should point $this->db (or the db Attribute of the dbBills class) as a new instance of the dbAccess class that we created last week.
for examples of this please refer to
http://us2.php.net/manual/en/ref.classobj.php
pay special attention to the first two examples and how they relate to one another.
for Insert you are inserting a record into the database. The values should already be assigned to the class attributes. You want to use the SQL insert command on conjunction with mysql_query.
For more information on this function and examples please refer to:
http://www.php.net/mysql_query
for update, what you have is completely wrong. What you want to do is update the record pointed to by $id with the values that are currently in the class attributes. For this you will use the mysql update command and the php mysql_query function.
For more information on this function and examples please refer to:
http://www.php.net/mysql_query
for delrec, again this is completely wrong. You want to use the sql DELETE function to delete the record pointed to by the $id variable.
For more information and examples refer to:
[url]http:///www.php.net/mysql_query[/url]
for retrieve, you will use the select command of sql and the mysql_query function of php to retrieve the record pointed to by $id into the class attributes.
Once you've gotten these we'll move onto IDList and Search.
Ok,
I got alot of work on my plate reading all this.
Will catch you tommorow with a completed functions.
I think I grasp what your saying now, or at least partialy!
Later.
I think I have it right now!
Check it out!
Your close to having the basic functions down. The only two corrections are
1) return a 1 for success not a 0
2) $this->BillName not $BillName. $BillName is a variable local to this function $this->BillName is a class attribute.
now once you have the corrections in place for the basic functions let's think of a couple of things.
1) what if an invalid key is specified in $id?
2) do you really want to die on the user or do you want to keep running and show them a nicely formatted error?
3) how can you use the functions in dbAccess to get the mysql_ commands out of this file?
4) is there an easy, or have you already coded a, method for error checking what the user provides to $id?
Originally posted by drawmack
Your close to having the basic functions down. The only two corrections are
1) return a 1 for success not a 0
2) $this->BillName not $BillName. $BillName is a variable local to this function $this->BillName is a class attribute.
Ok, I think I corrected the problem. see the attachement.
Originally posted by drawmack
now once you have the corrections in place for the basic functions let's think of a couple of things.
1) what if an invalid key is specified in $id?
See attachement.
2) do you really want to die on the user or do you want to keep running and show them a nicely formatted error?
See attachement
3) how can you use the functions in dbAccess to get the mysql_ commands out of this file?
Don't know !
4) is there an easy, or have you already coded a, method for error checking what the user provides to $id?
hmmmmm, not sure how to do that!
What happens when a query fails even if the id checks out, like say the rest of the data is screwy?
I don't know !
didn't you catch and report failed queries in dbaccess? don't you think you should do the same thing here?
If this is what your talking about, the function has no code in it.
Snip from dbAccess.php
function dbAccess() {
/*This is the constructor function which is automatically executed whenever
we create a new instance of this class.
This particular class requires no instantiation but this function is included for completeness*/ } //end dbAccess
If this is not, then I don't understand what your getting at or what part of code you mean. Sorry!
Do you mean, for example, change this:
$this->error = "Invalid variable ($ID) passed to DelRec. <br>\n";
To be this:
$this->error = "Invalid variable ($ID) passed to DelRec: " . __FILE__ . " on line " . __LINE__ . mysql_error();
do me a favor upload your most recent dbBills.php file please?
Here it is