Jump to content

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in


OAFC_Rob

Recommended Posts

I'm stuck on a problem that i've not encountered before. A couple of weeks ago my PC died meaning I had to install a newer version of XAMMP onto my laptop, and this is the first time this message has popped up any ideas.

 

I get the following error message;

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\innovationation\commonResources\dbConnection\dbConnection.php on line 38

 

It firstly started off as saying that I was passing it a string through when it shouldn't so I broke the SQL down a bit more to the basic level, and then this one happened  :shrug:

 

 

if($errors==0 && isset($_POST['contactSubmitted']))
					{#OPEN IF INSERT & SEND EMAIL
						$sql = 	"
								INSERT INTO tbl_contact_log
									(
									fName,
									surname,
									contactNum,
									email,
									comments
									)
								VALUES
									(
									'test',
									'testing',
									'01610000000',
									'[email protected]',
									'this is a test'

									)
								";

						#die("<br/><br/>".$sql);
						$results = $database->sqlQuery($sql);
						if($database->affectedRows($results)>0)
						{
							echo 	"
									<p>
										YEAH BITCH!
									</p>
									";
						}

 

 

public function sqlQuery($sql)
        {
            #NEED TO ADD EXTRA FAIL SAFES IF TABLE DOESN'T EXIST
            $result = mysql_query($sql, $this->dbConnection) OR trigger_error(mysql_error($sql),E_USER_ERROR); 
            if(mysql_num_rows($result)>0)
            {
              $this->confirmResult($result);
              return $result;   
            }
            else
            {
               $msg = "Sorry but there seems to be an no data for this query<br/><br/>". $sql;
               return $msg;
            }
            
        }



public function escapeValue($value)
        {
            $magic_quotes_active = get_magic_quotes_gpc();
            $new_enough_php = function_exists("mysql_real_escape_string"); //i.e. PHP >= v4.3.0
            if($new_enough_php)
            {
                //PHP v4.3.0 or higher, undo any magic quote effects so mysql_real_espace_string can do the work
                if($magic_quotes_active)
                {
                    $value = stripslashes($value);
                }
                $value = mysql_real_escape_string($value);
            }
            else
            {
                //before PHP v4.3.0, if magic quotes aren't already on the add slashes manually
                if(!$magic_quotes_active)
                {
                    $value = addslashes($value);
                }
                //if magic quotes are active, then the slashes already exist
            }
            return $value; 
        }


public function affectedRows()
        {
            return mysql_affected_rows($this->dbConnection);
        }

I've just checked the database and it has been inserting into, despite the error message  :shrug:

 

I have also just inserted the died out SQL into a program which inserted with no problems, I have also changed the sqlQuery in the db connection class to this

 

public function sqlQuery($sql)
        {
            #NEED TO ADD EXTRA FAIL SAFES IF TABLE DOESN'T EXIST
            $result = mysql_query($sql, $this->dbConnection) OR trigger_error(mysql_error($sql),E_USER_ERROR); 
		$this->confirmResult($result);
		return $result;
            #if(mysql_num_rows($result)>0)
            #{
            #  $this->confirmResult($result);
            #  return $result;   
            #}
            #else
            #{
            #   $msg = "Sorry but there seems to be an no data for this query<br/><br/>". $sql;
            #   return $msg;
            #}
            
        }

 

But still no luck as I am no getting the following;

 

Warning: mysql_affected_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\innovationation\commonResources\dbConnection\dbConnection.php on line 107

 

which relates to this bit

 

public function affectedRows($result)
        {
            return mysql_affected_rows($result);
        }

mysql_affected_rows takes the db link as a parameter, which is what you had in the code posted in the first post in this thread. Why did you change your code to use the result resource in the mysql_affected_rows statement?

I have no idea now, my brain is fried, it is 21:00 here and ive been coding since 08:30, ive changed it back and it seems to be working.

 

How can I improve upon this?

 

public function sqlQuery($sql)
        {
            #NEED TO ADD EXTRA FAIL SAFES IF TABLE DOESN'T EXIST
            $result = mysql_query($sql, $this->dbConnection) OR trigger_error(mysql_error($sql),E_USER_ERROR); 
		$this->confirmResult($result);
		return $result;
            #if(mysql_num_rows($result)>0)
            #{
            #  $this->confirmResult($result);
            #  return $result;   
            #}
            #else
            #{
            #   $msg = "Sorry but there seems to be an no data for this query<br/><br/>". $sql;
            #   return $msg;
            #}
            
        }

 

I'm soo tired, going to stop soon and go to bed to start it all over again  :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.