Jump to content

Var Undefined $ mysql_num_rows HELP!


wchamber22

Recommended Posts

Hi all,

 

I have been running into a couple of errors messages that I have not been able to debug (below):

 

1. Undefined var Use1

2. mysql_num_rows(): supplied argument is not a valid MySQL result resource

 

My code is as follows:

<?php 
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
$results = "";
if(isset($_GET['PlantID'])) {
include_once "scripts/connect_to_mysql.php";
$PlantID = $_GET['PlantID'];
$sql = mysql_query("SELECT * FROM plants WHERE PlantID='$PlantID'");
$plantCount = mysql_num_rows($sql);
if($plantCount > 0) {
	while ($row = mysql_fetch_assoc($sql)) {
		$PlantID = $row["PlantID"];
		$BotanicalName = $row["BotanicalName"];
		$CommonName = $row["CommonName"];
		$HardinessZones = $row["HardinessZones"];
		$Type = $row["Type"];
		$Height = $row["Height"];
		$Spread = $row["Spread"];
		$Flower = $row["Flower"];
		$BloomTime = $row["BloomTime"];
		$Foliage = $row["Foliage"];
		$FallColor = $row["FallColor"];
		$Fruit = $row["Fruit"];
		$Light = $row["Light"];
		$Soil = $row["Soil"];
		$Growth = $row["Growth"];
		$Trimming = $row["Trimming"];
		$Fertilization = $row["Fertilization"];
		$OtherMaintenance = $row["OtherMaintenance"];
		$Use1 = $row["Use1"];
		$Use2 = $row["Use2"];
		$Use3 = $row["Use3"];
		$Use4 = $row["Use4"];
		$Use5 = $row["Use5"];
		$UseDesc1 = $row["UseDesc1"];
		$UseDesc2 = $row["UseDesc2"];
		$UseDesc3 = $row["UseDesc3"];
		$UseDesc4 = $row["UseDesc4"];
		$UseDesc5 = $row["UseDesc5"];
		$Image1 = $row["Image1"];
		$Image2 = $row["Image2"];
		$Image3 = $row["Image3"];
		$Image4 = $row["Image4"];
		$Image5 = $row["Image5"];
		$ImageDesc1 = $row["ImageDesc1"];
		$ImageDesc2 = $row["ImageDesc2"];
		$ImageDesc3 = $row["ImageDesc3"];
		$ImageDesc4 = $row["ImageDesc4"];
		$ImageDesc5 = $row["ImageDesc5"];
	}
} else {
	$results = "<h1>No Data to Run this Page!</h1>";	
}
}
?>
<?php
session_start();
// See if they are a logged in member by checking Session data
$toplinks = "";
$booklinks = ""; 
if (isset($_SESSION['memberID'])) {
    $memberID = $_SESSION['memberID'];
    $username = $_SESSION['username'];
$toplinks = '<a href="memberaccount.php?id=' . $memberID . '">Welcome, ' . $username . '!</a>   |    
<a href="memberaccount.php?id=' . $memberID . '">My Account</a>   |    
<a href="book.php">Your Plant Book</a>   |   
<a href="logout.php">Log Out</a>';
$booklinks = '<form name="add_to_book" method="post" action="plantdetails.php">
			 <input name="memberID" type="hidden" value="' . $memberID . '" />
			 <input name="PlantID" type="hidden" value="' . $PlantID . '" />
			 <input name="BotanicalName" type="hidden" value="' . $BotanicalName . '" />
			 <input name="CommonName" type="hidden" value="' . $CommonName . '" />
			 <input name="Use" type="hidden" value="' . $Use1 . '" />
			 <input name="add_to_book_btn" type="submit" value="Add ' . $BotanicalName . ' (' . $Use1 . ') to Your Book!" />
			 </form>';
} else {
$toplinks = '<a href="join.php">Join Now</a>   |    
<a href="login.php">Login</a>';
$booklinks = '<h1>You must be logged in to Add Plant Pages and Create Plant Books! <img src="images/AddtoBook.gif" border="0" /></h1>';
}
?>
<?php
$errorMsg = "";
if(isset($_POST['memberID'])) {
include_once "scripts/connect_to_mysql.php";
$memberIDtemp = $_POST['memberID'];
$PlantID = $_POST['PlantID'];
$BotanicalName = $_POST['BotanicalName'];
$CommonName = $_POST['CommonName'];
$Use = $_POST['Use'];	
$sqlCheck = mysql_query("SELECT * FROM book_temp WHERE PlantID='$PlantID' AND Use='$Use'");
$plantCountCheck = mysql_num_rows($sqlCheck);
if($plantCountCheck > 0) {
	$errorMsg = "<h1>This Plant and Landscape Use is already in Your Book! Please select another Plant or Landscape Use.</h1>";
} else {
mysql_query("INSERT INTO book_temp (memberID, PlantID, BotanicalName, CommonName, Use) VALUES ('$memberIDtemp', '$PlantID', '$BotanicalName', '$CommonName', '$Use')");	
header("location: book.php");
exit();
}
}
?>

The particular errors are on the following lines:

				 
<input name="Use" type="hidden" value="' . $Use1 . '" />
<input name="add_to_book_btn" type="submit" value="Add ' . $BotanicalName . ' (' . $Use1 . ') to Your Book!" />
$plantCountCheck = mysql_num_rows($sqlCheck);

 

Any help would be superb, Thanks in advance!

 

Bill C.

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.