wchamber22 Posted March 12, 2011 Share Posted March 12, 2011 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 https://forums.phpfreaks.com/topic/230393-var-undefined-mysql_num_rows-help/ Share on other sites More sharing options...
trq Posted March 12, 2011 Share Posted March 12, 2011 You need to check your query returns a result before you go ahead and use it. Link to comment https://forums.phpfreaks.com/topic/230393-var-undefined-mysql_num_rows-help/#findComment-1186490 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.