Jump to content

Error Help


vmicchia

Recommended Posts

Hi I am working on a pretty simple script at the moment. I keep getting this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/stay/public_html/index.php on line 26.

 

Here is my code

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<div id="outerContainer" style="width:1024px; border:thin; border-color:#000000">
<div id="imageContainer" style="width:500px;">
</div>
<div id="formContainer">
<form name="selectCushion" id="selectCushion" enctype="multipart/form-data" action="fabricSelect.php">
<?php include("includes/openDbConn.php");
$sql="SELECT cushionName, cushionDescription, cushionPrice, cushionImagePath FROM cushions";
//echo $sql;
$result = mysql_query($sql);
//echo $result;
//echo "This works";
if($result = 0){
	$num_results = 0;
	//echo "Past If";
}else{
	//echo "Past else";
	//echo $num_results;
	$num_results = mysql_num_rows($result);
}
for($i = 0; $i < $num_results; $i++){
	$row = mysql_fetch_array($result);
	echo "<input type='image' src='".trim($row["cushionImagePath"])."' height='' width='' alt='".trim($row["cushionDescription"])."'/>";
	//echo "<label>" trim($row["cushionName"]) "</label>";
} ?>

</form>
</div>
</div>
</body>
</html>

 

I have run the query in mySQL and it returns the correct data so that doesn't seem to be the problem.

Thanks for any help.

Link to comment
Share on other sites

on line 17 (if I counted backwards correctly)...

 

if($result = 0){

 

needs to be:

 

if($result == 0){ //with 2 equal signs

 

Instead of checking if $result is equal to zero, you're re-assigning the value of $result to 0.

Link to comment
Share on other sites

on line 17 (if I counted backwards correctly)...

 

if($result = 0){

 

needs to be:

 

if($result == 0){ //with 2 equal signs

 

Instead of checking if $result is equal to zero, you're re-assigning the value of $result to 0.

 

Thanks so much for catching that. I copied some of the code from an old project so I guess I just expected it to be working and right. Much appreciated.

 

use this instead

 

while ( $row = mysql_fetch_array($result) {

  print $row['field'];

}

 

I will try that I appreciate the advice very much.

 

 

It works great now. Much appreciated.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.