Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > Mysql question?
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 8th November 00:06
bob sabiston
External User
 
Posts: 1
Default Mysql question?



Hi,
Is this a good place to ask a newbie question about mySql and PHP? I
wasn't sure if I should ask in a mysql group instead.

I am getting an error
"PHP Fatal error: Call to a member function free() on a non-object"

It happens when I call the second $result->free() below. I do a query for a
username, and if it doesn't exist then I want to create it. The first call
to $result->free() works. However then I do a query to insert the user and
get a new result. Trying to free that one gives me the error. The result
is nonzero -- why does it crash?

$query = "select * from users where username = '%".$username."%'";
$result = $db->query($query);
$num_results = $result->num_rows;

if ($num_results == 0) {
$result->free();

// no user -- create one
$query = "insert into users values
(NULL,'".$username."', '".$email."', '".$password."')";
$result = $db->query($query);

if ($result) {
$result->free(); <==== CRASHES HERE

Thanks for any help!
Bob
  Reply With Quote


 


Reply


Thread Tools
Display Modes




666