returning a variable from a class function? plus other probs
| From: | Kirk Babb | Date: | Sun, 05 Oct 2003 00:27:44 +0000 |
| Subject: | returning a variable from a class function? plus other probs | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-165066@lists.php.net to get a copy of this message | ||
I'm new at OO and still a newbie at PHP despite hacking away at it for a
while (admittedly off and on). I'm creating a signup form for alumni of our
department, and I'm trying to verify that they have not signed up previously
before allowing their data to be inserted. Trouble has ensued! :)
In the following code:
class alumnus {
function
addAlum($fname,$lname,$tel,$address,$city,$state,$zipcode,$country,$email) {
$conxn = mysql_connect('localhost','root','redtail.7') or
fail("Could
not connect: ".mysql_error());
$dbSelect = mysql_select_db("alumni", $conxn) or fail("Could not select
database: ".mysql_error());
$chk = "Select id, fname from contact_info where email =" . $email;
$result = mysql_query($chk);
$dataSet = mysql_fetch_array($result);
$fields = mysql_num_fields($dataSet);
if ($fields=="0") {
$insertData = "INSERT into contact_info
(fname,lname,tel,address,city,state,zipcode,country,email)
VALUES
('$fname','$lname','$tel','$address','$city','$state','$zipcode','$country',
'$email')";
$query = mysql_query($insertData);
if ($query) {
$bool="true";
return $bool;
}
}
}
I keep getting "supplied argument is not a valid MySQL result resource" for
the lines using mysql_fetch_array and mysql_num_fields - I've looked up the
functions but it doesn't seem like I'm misusing them. PLUS my $bool doesn't
show up outside like I'd like it to. Can somebody guide me on the right
path here?
Thanks!