5 Replies - 657 Views - Last Post: 20 July 2010 - 11:09 AM Rate Topic: -----

#1 James Bond C++ Spy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 132
  • Joined: 03-October 07

supplied argument is not a valid MySQL

Posted 20 July 2010 - 06:44 AM

Here is the code:
<?php

$con = mysql_connect("localhost","user","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result1 = mysql_query("SELECT employee.LastName, employee.FirstName, annual.Emp_Id,  
annual.harassment, annual.bbp, annual.loto, annual.hazcomm, annual.ppe, annual.evacuation, annual.drug  

FROM employee, annual 

Where employee.Emp_Id=ms.Emp_Id 
AND employee.Emp_Id<>'60' 
AND employee.Emp_Id<>'68' 
AND employee.Emp_Id<>'8' 
AND employee.Emp_Id<>'67' 
AND employee.Emp_Id<>'80' 
AND employee.Emp_Id<>'79' 
AND employee.Emp_Id<>'75' 
AND employee.Emp_Id<>'56' 
AND employee.Emp_Id<>'76' 
AND employee.Emp_Id<>'5'
AND employee.Emp_Id<>'87' 
AND employee.Emp_Id<>'83' 
AND employee.Emp_Id<>'86'
AND employee.Emp_Id<>'84'
AND employee.Emp_Id<>'92'
AND employee.Emp_Id<>'81'
AND employee.Emp_Id<>'72'

ORDER BY employee.LastName
");

echo "<table border='1'>
<tr>
<th>Employee ID</th>
<th>Last Name</th>
<th>First Name</th>
<th>Harassment</th>
<th>BBP</th>
<th>LOTO</th>
<th>Haz Comm</th>
<th>PPE</th>
<th>Evacuation</th>
<th>TN Drug Free</th>
</tr>";

(LINE 89) while($row = mysql_fetch_array($result1))
  {
  echo "<tr>";
  echo "<td>" . $row['Emp_Id'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['harassment'] . "</td>";
  echo "<td>" . $row['bbp'] . "</td>";
  echo "<td>" . $row['loto'] . "</td>";
  echo "<td>" . $row['hazcomm'] . "</td>";
  echo "<td>" . $row['ppe'] . "</td>";
  echo "<td>" . $row['evacuation'] . "</td>";
  echo "<td>" . $row['drug'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);

?>



Here is the error I get:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/Training/SearchResultsAnnual.php on line 89

Thanks for any help. I have several .php files that have the same error, this was working perfect but now errors. One of the files work perfect (basically the same code)

Is This A Good Question/Topic? 0
  • +

Replies To: supplied argument is not a valid MySQL

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,333
  • Joined: 08-June 10

Re: supplied argument is not a valid MySQL

Posted 20 July 2010 - 06:47 AM

your query fails (resp. returns false). you should always test the return value of your query like you do for the connection.
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,584
  • Joined: 08-August 08

Re: supplied argument is not a valid MySQL

Posted 20 July 2010 - 07:21 AM

The $result1 is merely a resource. You need to fetch the array. Try it this way:

$query = "Humongously long query here";
echo $query."<br>"; // So you can see if it is built the way you expect and you can test it in phpmyadmin!
$dbdata = mysql_query($query);
$result1 = mysql_fetch_assoc($dbdata);


This post has been edited by CTphpnwb: 20 July 2010 - 07:21 AM

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,333
  • Joined: 08-June 10

Re: supplied argument is not a valid MySQL

Posted 20 July 2010 - 07:24 AM

line 4 will throw an error if $dbdata is false due to an SQL error.
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,584
  • Joined: 08-August 08

Re: supplied argument is not a valid MySQL

Posted 20 July 2010 - 10:57 AM

Yes, you could do the 'or die(mysql_error());' for debugging purposes. Better yet would be to use Valek's error logging code.

This post has been edited by CTphpnwb: 20 July 2010 - 11:25 AM
Reason for edit:: Fixed url (I think)

Was This Post Helpful? 0
  • +
  • -

#6 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: supplied argument is not a valid MySQL

Posted 20 July 2010 - 11:09 AM

There are errors in the way that's loading up (the PrettyPrint thing doesn't like search highlighting apparently).

$result = mysql_query($query);
if(!$result)
{
     error_log($query);
     error_log(mysql_error());
     echo "There was an error with a database query.  It has been logged.";
     die;
}


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1