0

I am getting a warning message which I don't understand why and unable to resolve, (see below)

Warning: Supplied argument is not a valid MySQL result resource in /detail.php on line 34

Here is my code:

$rs = mysql_query($strSQL);
 $strSQL = "SELECT * FROM <tablename> WHERE id=" . $_GET["serviceName"];
 // Loop the recordset $rs
  while($row = mysql_fetch_array($rs))   **(line 34) here ***
{
 echo $row['ID']."<br />";
       echo $row['serviceName']."<br />";
     // Close the database connection
mysql_close();
?>

</dl>
<p><a href="li.php">Return to the list</a></p>
  </body>

</html>

thanks in advance, I am not getting any of the data on this webpage either,thanks...singhy

user3723480
  • 83
  • 2
  • 9
  • You executing query and than assigning query to `$strSQL` variable. Take it above the `mysql_query` statement. – Rikesh Jun 13 '14 at 08:52
  • why `$rs = mysql_query($strSQL);` is before setting the variable ? – Abhik Chakraborty Jun 13 '14 at 08:53
  • 1
    **Waring:** [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – Rikesh Jun 13 '14 at 08:53
  • What is the data type of `id`? – Mark Miller Jun 13 '14 at 08:55
  • hi abhik,rikesh and mark for quick response, thanks it worked ok, I can not seem to get the data displayed, I am using echo "
    Name:
    " . $row["serviceType"] . " " . $row["serviceName"] . "
    "; thanks...singhy
    – user3723480 Jun 13 '14 at 09:20

2 Answers2

0

You need to do it like this

 $strSQL = "SELECT * FROM gu_service_cat WHERE id=" . $_GET["serviceName"];
 $rs = mysql_query($strSQL);

Because before setting value to the variable you are using it in the query. This is why it is throwing the error.

웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
0

The query is failing - you need to wrap quotes around strings in MySQL:

$strSQL = "SELECT * FROM gu_service_cat WHERE id = '" . $_GET["serviceName"] . "'";

plus, the $rs should be BELOW the $strSQL...

Farkie
  • 3,307
  • 2
  • 22
  • 33
  • hi farcie thanks yes it worked but I can not get the data to display I am using echo "
    Name:
    " . $row["serviceType"] . " " . $row["serviceName"] . "
    "; thanks in advance...singhy
    – user3723480 Jun 13 '14 at 09:17