PHP - $row[1] Undefined, Mysql_num_rows = 2 ?
I know im being blind today but can someone point out why:
Code: [Select] $query = "SELECT peopleID FROM numpeople WHERE ID = '3';"; $result = mysql_query($query) or die("failed."); $row = mysql_fetch_row($result); $numpeople = mysql_num_rows($result); echo "<br /> row $row[1]"; echo "<br />numpeople $numpeople"; $numpeople returns 2, but $row[1] is undefined? $row[0] is fine. (The value of $row[0] is 7 and $row[1] should be . This is the second error that I really cant see.... Similar TutorialsHi 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: Code: [Select] <?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: Code: [Select] <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. Hello, I have just upgraded my wampserver and with it MySQL, PHP and PhpMyAdmin versions. And my scripts, which ran normally before, not burst hundreds of undefined variable and undefined index notices. I realize it's "notices", not "errors" but this is quite irritating. I believe it might be due to some upgrade in PHP scripting rules or something but I don't know what. I hope you can help me. The first type of notice is "undefined variable". This function will return the notice if I remove the bold red line, where I define the variable as empty before I use it in the loop. I didn't need to do this before. function statistics($array) { [color=red][b]$list = '';[/b][/color] if(is_array($array)) { foreach($array as $name => $value) { // Rip out the name of the client. $list .= "<li>".$name." - "; // set an integer so we know how many tier2 values we have read. $x = 0; foreach($value as $difference => $sum_total) { // if this is the more than the first tier2 values, use a '+' between the units. $list .= (++$x > 1) ? " + ".$sum_total." ".$difference : $sum_total." ".$difference; } // close the line out. $list .= "</li>"; } } return $list; } To avoid the 10+ like notices on the page I declare them empty before the variable's first occurrence. But this sounds stupid to me. Wasn't this one of PHP's benefits, not to have to declare the variable before using it? I also get about 30+ undefined index notices, e.g. Quote Notice: Undefined index: COMPANY XXX in F:\wamp\www\Project Management\main.php on line 37 Notice: Undefined index: USD in F:\wamp\www\Project Management\main.php on line 37 Notice: Undefined index: USD in F:\wamp\www\Project Management\main.php on line 41 Here are those lines: $income_total = calculate("income"); foreach($income_total as $row) { $clientID = $row['clientID']; $clientname = $row['clientname']; //$client = "<a href=\"index.php?page=Client&do=view&clientID=$clientID\">".$clientname."</a>"; $client = "<a href=\"index.php?page=Project&do=view&sortby=$clientID\">".$clientname."</a>"; $currency = $row['currency']; $client_sum = $row['client_sum']; $year_sum = ''; $year_sum += $client_sum; $income = ''; $income[$client][$currency] += $client_sum; $income_list = statistics($income); $income_all = ''; $income_all[$currency] += $client_sum; } Line 37 is: Quote $income[$client][$currency] = It's the values assigned to $client and to $currency that seem to cause the notice. How do I deal with this? I don't just want to turn error/notice display off, I want to resolve this issue. Hi I am trying to create a login script using the code below Code: [Select] <?php session_start(); include_once('includes/connect.php'); $user=$_POST['username']; $password=$_POST['password']; //check if username and password exists $checkuser=mysql_query("SELECT * from `tbl_users` where username = '$user' and password=md5('$password')"); if(mysql_num_rows($checkuser) > 0) //login name was found //if they do return to home page with relevant include { $user_row = mysql_fetch_array($checkuser); $_SESSION['auth']="yes"; $_SESSION['logname'] = $user_row['forename']; $_SESSION['usertype'] = $user_row['usertype']; header("Location: index.php"); exit; } //if not display login form with message that says logon details are incorrects else { echo('Do something else'); } ?> However I get a message saying that mysql_num_rows is not a valid resource. Any ideas where I am going wrong? Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource. if ($_POST['subscribe']) { $email_subscribe = $_POST['email']; if (mysql_num_rows(mysql_query("SELECT * FROM newsletter WHERE email=$email_subscribe"))) { mysql_query("UPDATE newsletter SET active=1 WHERE email=$email_subscribe") or die ('Error updating the database'); echo "Thank you for subscribing!"; echo "<meta http-equiv=\"refresh\" content=\"0;url=javascript:history.back();\">"; } else { mysql_query("INSERT INTO newsletter (`email`,`active`) VALUES ('$email_subscribe', '1')"); echo "Thank you for subscribing!"; echo "<meta http-equiv=\"refresh\" content=\"0;url=javascript:history.back();\">"; } } elseif ($_POST['unsubscribe'] != 0) { $email_unsubscribe = $_POST['email']; if (mysql_num_rows(mysql_query("SELECT * FROM newsletter WHERE email=$email_unsubscribe"))) { mysql_query("UPDATE newsletter SET active=0 WHERE email=$email_unsubscribe") or die ('Error updating the database'); echo "You have been unsubscribed."; echo "<meta http-equiv=\"refresh\" content=\"5;url=javascript:history.back();\">"; } else { echo "Email does not exist."; echo "<meta http-equiv=\"refresh\" content=\"5;url=javascript:history.back();\">"; } Hello, I am having a problem.. I get this message " Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in... " whenever i am trying to work my log in script. The script is: Quote <?php $host="localhost"; $username="root"; $password="pass"; $db_name="webDB"; $table_name="webmembers"; mysql_connect($host, $username, $password) or die ('Unable to connect'); mysql_select_db($db_name) or die ('Error'); $uname= $_POST['uname']; $pword= $_POST['pword']; $urname= stripslashes($uname); $pword= stripslashes($pword); $uname= mysql_real_escape_string($uname); $pword= mysql_real_escape_string($pword); $sql= "SELECT * FROM '$table_name' WHERE username: '$uname' and password: '$pword'"; $result=mysql_query($sql); $count= mysql_num_rows($result); <----------- problem if ($count == 1) { session_register($uname); session_register($pword); header("location: loginsuccess.php"); } else { echo $result,$count; echo "Wrong Username and Password"; } mysql_close(); ?> and Quote "loginsuccess.php" <?php session_start(); if(!sesssion_is_registered($uname)) { header("location: mainpage.php"); } ?> <html> <head> </head> <body> Log in Successful </body> </html> why do i get this warning? what am i doing wrong? Is there any simpler way to create a log in page but being secure as well? Thank in advance. I'm trying to loop out 10 rows of comment, but this code only displays comment one time, how do I display all rows? $query = "SELECT * FROM ".$prefix."comments WHERE userto = '".$user."' ORDER BY comment DESC LIMIT 0, 10"; $result = mysql_query($query); $num = mysql_num_rows($result); //Loop out code $i=0; while ($i < $num) { $comments=@mysql_result($result,$i,"comment"); $i++; } $sql = "SELECT current FROM LIBusersX WHERE UserKey = '$Key' AND K_Type = $type AND current > 0 "; // echo $sql . "<br>"; $query = mysql_query ($sql) or die ("E112-100A"); $total = mysql_num_rows($query) or die ("E112-101A");Hi I have a website with a few users. I set up a system so that some users (as a trial) can only log on a fixed number of times. I have a field called current that counts down to zero. However when it reaches zero I get my error E112-101A Why do I get an error? Surely I should just get $total = 0 please help! I am getting undefined index and offset when I duplicated my SEARCH page for when logged in here is my code Code: [Select] <?php include_once("config.php"); include_once("functions.php"); // Check user logged in already: checkLoggedIn("yes"); ?> <!doctype html> <html> <head> <title>Retro and Vintage</title> <meta name="description" content="xxx" /> <meta name="keywords" content="xxx" /> <meta name="Content-Language" content="en-gb" /> <meta name="robots" content="FOLLOW,INDEX" /> <meta name="revisit-after" content="2 days" /> <meta name="copyright" content="jbiddulph.com" /> <meta name="author" content="John Biddulph - Professional web site design and development in the south of england mainly worthing and brighton" /> <meta name="distribution" content="Global" /> <meta name="resource-type" content="document" /> <link rel="stylesheet" type="text/css" href="css/reset.css" /> <link rel="stylesheet" type="text/css" href="css/style.css" title="default" /> <link rel="alternate stylesheet" type="text/css" href="css/style1.css" title="1" /> <link rel="alternate stylesheet" type="text/css" href="css/style2.css" title="2" /> <script type="text/javascript" src="js/stylechanger.js"></script> <script type="text/javascript" src="js/jquery-1.2.1.pack.js"></script> <script type="text/javascript"> function lookup(inputString) { if(inputString.length == 0) { // Hide the suggestion box. $('#suggestions').hide(); } else { $.post("rpc.php", {queryString: ""+inputString+""}, function(data){ if(data.length >0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } }); } } // lookup function fill(thisValue) { $('#inputString').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } </script> </head> <body> <?php if($messages) { displayErrors($messages); }?> <header> <div id="title"> <h1>My Pub Space <a href="#" onClick="setActiveStyleSheet('default'); return false;"><img src="images/0.gif" width="15" height="15" border="0" alt="css style" /></a> <a href="#" onClick="setActiveStyleSheet('1'); return false;"><img src="images/1.gif" width="15" height="15" border="0" alt="css style" /></a> <a href="#" onClick="setActiveStyleSheet('2'); return false;"><img src="images/2.gif" width="15" height="15" border="0" alt="css style" /></a> <span> <form method="post" class="textbox" action="search1.php"> City/Town: <input type="text" size="26" class="searchbox" value="" id="inputString" onKeyUp="lookup(this.value);" onBlur="fill();" /> <div class="suggestionsBox" id="suggestions" style="display: none;"> <img src="images/upArrow.png" style="position: relative; top: -36px; left: 105px; z-index:1;" alt="upArrow" /> <div class="suggestionList" id="autoSuggestionsList"> </div> </div> <input type="image" src="images/go.png" height="30" with="30" value="GO" /> </form> </span> </h1> </div> </header> <nav> <ul> <li class="selected"><a href="#">Home</a></li> <li><a href="#">Pubs</a></li> <li><a href="#">Members</a></li> <li><a href="#">Events</a></li> <li><a href="#">Register</a></li> </ul> </nav> <section id="intro"> <header> <h2>Your social guide to going down the pub, online!</h2> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p> <img src="images/pub.jpg" alt="pub" /> </section> <div id="content"> <div id="mainContent"> <section> <article class="blogPost"> <header> <h2>This is the title of a blog post</h2> <p>Posted on <time datetime="2009-06-29T23:31+01:00">June 29th 2009</time> by <a href="#">Mads Kjaer</a> - <a href="#comments">3 comments</a></p> </header> <?php // drop out of PHP mode to display the plain HTML: $Townsearch = $_GET['rsTown']; echo $Townsearch; // Delimiters may be slash, dot, or hyphen list($Town, $County) = split('[,]', $Townsearch); $tableName="pubs"; $targetpage = "search1.php"; $limit = 20; $query = "SELECT COUNT(*) as num FROM $tableName WHERE rsTown LIKE '$Town%'"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages['num']; $stages = 3; $page = mysql_escape_string($_REQUEST['page']); if( isset($_REQUEST['page']) && ctype_digit($_REQUEST['page']) ) { $page = (int) $_GET['page']; $start = ($page - 1) * $limit; }else{ $start = 0; } // Get page data $query1 = "SELECT * FROM $tableName WHERE rsTown LIKE '$Town%' LIMIT $start, $limit"; $result = mysql_query($query1); // Initial page num setup if ($page == 0){$page = 1;} $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total_pages/$limit); $LastPagem1 = $lastpage - 1; $paginate = ''; if($lastpage > 1) { $paginate .= "<div class='paginate'>"; // Previous if ($page > 1){ $paginate.= "<a href='$targetpage?page=$prev'>previous</a>"; }else{ $paginate.= "<span class='disabled'>previous</span>"; } // Pages if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } } elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few? { // Beginning only hide later pages if($page < 1 + ($stages * 2)) { for ($counter = 1; $counter < 4 + ($stages * 2); $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } $paginate.= "..."; $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>"; $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; } // Middle hide some front and some back elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2)) { $paginate.= "<a href='$targetpage?page=1'>1</a>"; $paginate.= "<a href='$targetpage?page=2'>2</a>"; $paginate.= "..."; for ($counter = $page - $stages; $counter <= $page + $stages; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } $paginate.= "..."; $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>"; $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; } // End only hide early pages else { $paginate.= "<a href='$targetpage?page=1'>1</a>"; $paginate.= "<a href='$targetpage?page=2'>2</a>"; $paginate.= "..."; for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } } } // Next if ($page < $counter - 1){ $paginate.= "<a href='$targetpage?page=$next'>next</a>"; }else{ $paginate.= "<span class='disabled'>next</span>"; } $paginate.= "</div>"; } echo $total_pages.' Results'; // pagination echo $paginate; ?> <ul> <?php while($row = mysql_fetch_array($result)) { echo '<li>'.$row['rsPubName'].', '.$row['rsTown'].', '.$row['rsCounty'].'</li>'; if ($_SESSION["rsUser"] == "admin") { echo "<a href=\"edit.php?PUBID=".$row['PubID']."\" class=\"small\">edit this pub</a>"; } } ?> </ul> </article> </section> <section id="comments"> <h3>Comments</h3> <article> <header> <a href="#">George Washington</a> on <time datetime="2009-06-29T23:35:20+01:00">June 29th 2009 at 23:35</time> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p> </article> <article> <header> <a href="#">Benjamin Franklin</a> on <time datetime="2009-06-29T23:40:09+01:00">June 29th 2009 at 23:40</time> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p> </article> <article> <header> <a href="#">Barack Obama</a> on <time datetime="2009-06-29T23:59:00+01:00">June 29th 2009 at 23:59</time> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p> </article> </section> <form action="#" method="POST" method="post"> <h3>Post a comment</h3> <p> <label for="name">Name</label> <input name="name" id="name" type="text" required /> </p> <p> <label for="email">E-mail</label> <input name="email" id="email" type="email" required /> </p> <p> <label for="website">Website</label> <input name="website" id="website" type="url" /> </p> <p> <label for="comment">Comment</label> <textarea name="comment" id="comment" required></textarea> </p> <p> <input type="submit" value="Post comment" /> </p> </form> </div> <aside> <section> <header> <h3>Members Login Area</h3> </header> <h4>Welcome <? print($_SESSION["rsUser"]); ?></h4> <a href="logout.php">Logout</a> </section> <section> <header> <h3>Archives</h3> </header> <ul> <li><a href="#">December 2008</a></li> <li><a href="#">January 2009</a></li> <li><a href="#">February 2009</a></li> <li><a href="#">March 2009</a></li> <li><a href="#">April 2009</a></li> <li><a href="#">May 2009</a></li> <li><a href="#">June 2009</a></li> </ul> </section> </aside> </div> <footer> <div> <section id="about"> <header> <h3>About</h3> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco <a href="#">laboris nisi ut aliquip</a> ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </section> <section id="blogroll"> <header> <h3>Blogroll</h3> </header> <ul> <li><a href="#">NETTUTS+</a></li> <li><a href="#">FreelanceSwitch</a></li> <li><a href="#">In The Woods</a></li> <li><a href="#">Netsetter</a></li> <li><a href="#">PSDTUTS+</a></li> </ul> </section> <section id="popular"> <header> <h3>Popular</h3> </header> <ul> <li><a href="#">This is the title of a blog post</a></li> <li><a href="#">Lorem ipsum dolor sit amet</a></li> <li><a href="#">Consectetur adipisicing elit, sed do eiusmod</a></li> <li><a href="#">Duis aute irure dolor</a></li> <li><a href="#">Excepteur sint occaecat cupidatat</a></li> <li><a href="#">Reprehenderit in voluptate velit</a></li> <li><a href="#">Officia deserunt mollit anim id est laborum</a></li> <li><a href="#">Lorem ipsum dolor sit amet</a></li> </ul> </section> </div> </footer> </body> </html> error lies on these lines Code: [Select] // drop out of PHP mode to display the plain HTML: $Townsearch = $_GET['rsTown']; echo $Townsearch; // Delimiters may be slash, dot, or hyphen list($Town, $County) = split('[,]', $Townsearch); my current code: Code: [Select] $Townsearch = $_REQUEST['rsTown']; list($Town, $County) = split('[,]', $Townsearch); ltrim($County,1); I am getting undefined index and undefined offset, so I tried this: Code: [Select] if $_REQUEST['rsTown'] == ''{ $Townsearch = ''; } else { $Townsearch = $_REQUEST['rsTown']; } but this brought back: Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in D:\retroandvintage.co.uk\wwwroot\main.php on line 6 Can someone please help? thanks I am pretty sure I defined these, by making it something like $blah="blah" and `blah` = ' {$blah}' So why am I getting these errors = Notice: Use of undefined constant petid - assumed 'petid' in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 38 Notice: Use of undefined constant adopter - assumed 'adopter' in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 41 Notice: Undefined variable: fulldate in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 44 Fatal error: Call to undefined function showpet_forum() in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 45 $time = mysql_query("SELECT * FROM `pets_adopted`"); $date = mysql_fetch_array($time); $fulldate = "$date[fulldate]"; $halfdate = "$date[halfdate]"; function check(){ $pid = mysql_real_escape_string($_GET['id']); $result = mysql_query("SELECT * FROM `pets_adopted` WHERE `id` = '{$pid}'"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $results = mysql_query("SELECT * FROM `pets_list` WHERE `id` = '{$row[petid]}'"); $pet = mysql_fetch_array($results); $results2 = mysql_query("SELECT * FROM `users` WHERE `id` = '{$row[adopter]}'"); $usercc = mysql_fetch_array($results2); There's the snippet. Thank you for any help. I am just really lost. I'm trying to check the number of results returned in a query. Currently there is one result being returned but i'm getting this error when I try to run line 38: Code: [Select] $num_rows = mysql_num_rows($ratings); Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/haas12/public_html/login/rateVideo.php on line 38 Rows Code: [Select] $ratingsQuery = "SELECT * FROM haas12_test.ratings "; $ratings = mysqli_query($conn, $ratingsQuery) or die ("Couldn't execute query."); $num_rows = mysql_num_rows($ratings); echo "$num_rows Rows\n"; Hi guys, one of the last questions from me for a while i hope lol i am trying to check if a phone number allready exists in a database using mysql_num_rows The code is this: Code: [Select] $SQL = "SELECT * FROM postcode WHERE phone = $phone"; $result = mysql_query($SQL); $num_rows = mysql_num_rows($result); if ($num_rows > 0) { $errorMessage = "It seems that this phone number is already been entered into our database"; } else {bla bla bla But i keep getting a warning message: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in I am at my wits end with this and done a lot of searching to try and find out why this is, but obviously i am dim and need it to be explained in english. Cheers! Get an error saying: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\admin\delete.php on line 16 Sorry, but we can not find an entry to match your query Surely this means the code has worked because of the last line, but i can't get rid of the error! $q = "DELETE FROM `stocklist` WHERE `Stock Number`='".$rec."'"; $res = mysql_query($q, $link) or die (mysql_error()); $anymatches = mysql_num_rows($res); if ($anymatches == 0) die ('Sorry, but we can not find an entry to match your query<br><br>'); echo '<h1>Entry has been deleted!</h1><br><br>'; mysql_close($link); Hi, This is my first post on phpfreaks[dot]com. I want some help on a php code i was writing this night watching a tutorial. Here's the code: if($cat && $name && $desc){ $sql7 = "SELECT * FROM `forum_cats` WHERE `id`='".$cat."'"; $res7 = mysql_query($sql7) or die(mysql_error()); if(mysql_num_rows($res7) == 0){ echo "The forum category you supplied does not exist!\n"; }else{ blablabla... } in cases like this, the mysql_num_rows() function was always working nicely. here for example: $sql3 = "SELECT admin FROM `users` WHERE `id`='".$_SESSION['uid']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); if(mysql_num_rows($res3)==0){ echo "Please login to your account!\n"; }else{ blablabla... } it's working here just fine. i canged my first code into this: if($cat && $name && $desc){ $sql7 = "SELECT * FROM `forum_cats` WHERE `id`='".$cat."'"; $res7 = mysql_query($sql7) or die(mysql_error()); $aaa = mysql_fetch_assoc($res7); if(sizeof($aaa) == 0){ echo "The forum category you supplied does not exist!\n"; }else{ blablabla... } now it works like it is supposed to, but i really want to know what i am doing wrong in the first part. EDIT: I can post a longer code so that maybe there is an error before the script gets to this part. I hope you will understand what i'm talking about Sorry for my English. thanks in advance, Resul. I am having trouble calling mysql_num_rows in my script. I get the error message "PHP Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\scripts\update.php on line 41". I have looked around online but can only find the my sql is not right. I am able to copy and past the sql into mysql workbench and it runs fine. Any help would be much appreciated. Code: [Select] $game_id = $row['id']; $game_name = $row['game_name']; print("updating game {$game_id}: {$game_name}" . PHP_EOL); $sql = "SELECT users.id, users.username, users.number_attended_games FROM users join game_sessions_users on game_sessions_users.user_id = users.id where game_sessions_users.game_session_id = " . $game_id; print($sql . PHP_EOL); $players = mysql_query($sql, $connection) or die(mysql_error($connection));; if(mysql_num_rows($players >= 1)){ while($player = mysql_fetch_array($players, MYSQL_ASSOC)){ print('updating player: ' . $player['username']); $number_attended_games = $player['number_attended_games']; $user_id = $player['id']; $sql = "UPDATE users SET number_attended_games = " . ($number_attended_games + 1) . ", user_level = " . ($number_attended_games / 10) . " WHERE id = " . $user_id; $update_result = mysql_query($sql, $connection); } } $sql = "UPDATE game_sessions SET completed = 1 WHERE id = " . $game_id; $update_result = mysql_query($sql, $connection); Here is my CODE which is showing some error: Code: [Select] <?php include('dbcon.php'); session_start(); $usname=$_POST['usname']; $password=$_POST['password']; $usname = stripslashes($usname); $password = stripslashes($password); $usname = mysql_real_escape_string($usname); $password = mysql_real_escape_string($password); $check="y"; $sql = "select * from usname where usname='$usname' and password='$password'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1) { $sqlq = "select * from usname where usname='$usname' and password='$password' and check='$check'"; $resultq=mysql_query($sqlq); $countq=mysql_num_rows($resultq); if($countq==1) {$_SESSION['usname']=$usname; header('location:fire.php');} else {$_SESSION['status']="Admin Didnt grant you the permission to access the things"; header('location:index.php');} } else {$_SESSION['status']="Wrong username and password"; header('location:index.php');} die(" "); ?> And here are the ERRORS when the username and passwords are correct but the check is not equal to 'y'.... Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\money\verify.php on line 18 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\money\verify.php:18) in C:\xampp\htdocs\money\verify.php on line 24 Please tell me where is the mistake........... When fetching results from a query I have always used the following method (the one i was taught) 1. get the query 2. if i know there might be more than one row returned, count the rows 3. use a for loop to get all the mysql_fetch_row results. Is there a more efficient way? eg, i am now writing a section that i know will either return one row or two, but never anymore, can i run a foreach on a mysql fetching function to get all the rows instead of counting first? (ie cutting out the middle man) I am getting the following warning with the code below.Can someone please point me why the warning ? Warning Code: [Select] Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/r.php on line 500 Code Code: [Select] $sql = "SELECT * FROM funeral WHERE name='".$name."' AND phone='".$phone."'"; $result = mysql_query($sql); if((mysql_num_rows($result)) == 0) { $insertsql = "INSERT INTO funeral (name, street, city, shrtstate, state, pincode, phone) VALUES ('".$name."', '".$street."', '".$city."', '".$shrtstate."', '".$state."', '".$pincode."', '".$phone."')"; $insert = mysql_query($insertsql); } Im trying to figure out if a user has already downloaded something so im seeing if they have a uid (user id) in the database along with the nid (note id) that they are trying to download. I echoed out the sql and it returned this: Quote SELECT * FROM purchases WHERE uid =1 AND nid =7 i manually ran that sql in phpmyadmin and it returned a couple rows. However my var $rows = mysql_num_rows($res2) has no value when i echo is out. Appriciate any help here is my code: Code: [Select] <?php $sql2 = "SELECT * FROM purchases WHERE uid =".$user_id." AND nid =".$id; $res2 = mysql_query($sql2) or die (mysql_error()); $rows = mysql_num_rows($res2); ?> |