PHP - Mysql_num_rows() Returns Error On Zero Rows
Hi I don't want errors on my page been reported on the web browser for all to see so I use this.
$total2 = mysql_num_rows($qCheckUser) or die ("Error1"); however if the query returns zero rows I get Error1 on the web page. This is not an error and I don't want to taje out the or die() Any sugestions. Similar TutorialsI have a html table displaying data from mysql database. I can count rows properly with mysql_num_rows but is there a way to echo which row number it is. What I want to do is count the rows ordered by cities and echo row number. Thanks for any help. I'm trying to write a php page that displays data from a JOIN query for a specific ID table view brandinfo ID, brand, discounttype 1, antioni, no discount brandproducts brandID, producttype, price 1, Tshirt, 20.00 1, Pants, 30.00 1, Shoe, 40.00 the returned result is 1 antioni, no discount, Tshirt, 20.00, 2 antioni, no discount, Pants, 30.00 3 antioni, no discount, Shoe 40.00 The way I want the page to be displayed is ------------------ Antioni (at the top) Table 1. Tshirt 20.00 2. Pants 30.00 3. Shoe 40.00 no discount (at the bottom) ---------------------------- How should I construct the PHP page from the result since they're retrieved as rows? 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"; 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 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! 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........... Hello there, I'm having a issue where when I run the following statement: $Session = $Module['MySQL']->RowCount("SELECT * FROM xhost_accounts WHERE (account_username = '{$Module['MySQL']->Escape($AccountUsername)}' OR account_email = '{$Module['MySQL']->Escape($AccountUsername)}') AND account_password = MD5('{$AccountPassword}')") == 1 ? true:false; I am proceeded by the following error: Code: [Select] Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Backend\MySQL-Module.php on line 49 Yet when I do the following statement: echo $Module['MySQL']->RowCount("SELECT * FROM xhost_accounts WHERE (account_username = '{$Module['MySQL']->Escape($AccountUsername)}' OR account_email = '{$Module['MySQL']->Escape($AccountUsername)}') AND account_password = MD5('{$AccountPassword}')") It gives me the output of 2 (That's the correct table row count)? Does anybody have any insight into why this could be happening thanks. Trying to get this to work but I know I'm missing something here. It's a form that is meant to update a record in DB. I am getting errore reference to first if (mysql_num_rows($result) == 1) in code and error message: Error has occurred. $connection = mysql_connect("xxxxxxxx","xxxxxx","xxxxxx"); if (!$connection) { die("Error connecting to database " . mysql_error()); } if (isset($_POST['submitted'])) $name = $_POST['name']; $email = $_POST['email']; $PHOTOGRAPHERID = $_POST['PHOTOGRAPHERID']; $query = "SELECT * FROM Photographers WHERE PHOTOGRAPHERID = $PHOTOGRAPHERID"; $result = mysql_query($query); if (mysql_num_rows($result) == 1){ // Make the query. $query = "UPDATE Photographers SET name='$name',email='$email' WHERE PHOTOGRAPHERID=$PHOTOGRAPHERID"; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/"."search.php"); } else { // If it did not run OK. echo '<h1 id="mainhead">System Error</h1> <p class="error">The name could not be edited due to a system error. We apologize for any inconvenience.</p>'; // Public message. echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. exit(); } } else { echo '<h1 id="mainhead">Error!</h1> <p class="error">Error has occurred.</p>'; } $query = "SELECT name, email FROM Photographer WHERE PHOTOGRAPHERID=$PHOTOGRAPHERID"; $result = @mysql_query ($query); // Run the query. // Create the form. echo '<h2>Edit a User</h2> <form action="update.php" method="post"> <p>Name: <input type="text" name="name" size="60" maxlength="60" value="' . $row[0] . '" /></p> <p>Email: <input type="text" name="email" size="60" maxlength="60" value="' . $row[1] . '" /></p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="PHOTOGRAPHERID" value="' . $id . '" /> </form>'; I have tried to create a basic login form. When I enter the username and password I get this error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in login.php on line 10 Code: [Select] <?php require("connection.php"); if($_SERVER["REQUEST_METHOD"] == "POST") { $username=mysql_real_escape_string($_POST['username']); $password=mysql_real_escape_string($_POST['password']); $password=md5($password); $sql="SELECT id FROM user WHERE username='$username' and password='$password'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1) { header("location: dashboard.php"); } else { $error="Invalid username or password"; } } ?> <form action="login.php" method="POST"> <table class="ltext"> <tr> <td> Username </td> <td> <input type="text" name="usename" class="input" /> </td> </tr> <tr> <td> Password </td> <td> <input type="password" name="password" class="input" /> </td> </tr> </tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> <input type="submit" value="Login" name="submit" class="input" /> <input type="reset" value="Clear" name="clear" class="input" /> </td> </tr> </table> </form> I can't figure out why I am getting that error message does anyone have any ideas? httpd-2.2.17-win32-x86-openssl-0.9.8o php-5.3.6-Win32-VC9-x86 mysql-5.5.11-win32 PHP code: $dbcnx = mysql_connect('localhost','root','admin'); Error message: No connection could be made because the target machine actively refused it. I used mysql.exe -u root -p to verify that mysql is working and using the right username and password. Any ideas how to fix it? Thanks, Richard friends if an array returns results as Array() how could i set an error message to it? i tried to do a if statement to the $variable but not working I have an facebook application, I look in the errors log routinely to see if there are any abnormalities. Today, I found one. Code: [Select] [Sun Feb 27 15:28:25 2011] [error] [client **.***.71.38] PHP Notice: Undefined offset: 0 in *** on line 33 [Sun Feb 27 15:28:26 2011] [error] [client **.***.71.38] Exception: 121: Param pid must be a valid merged photo id Now, I have no idea what is going on here. I have found the location of where the error occurs: Code: [Select] $fb_photo = $facebook->api("me/photos", "POST", $attachement); $FQLQuery = "SELECT object_id, pid, src_big, link FROM photo WHERE object_id = " . $fb_photo['id']; $FQLResult = $facebook->api(array('method' => 'fql.query', 'query' => $FQLQuery, 'access_token'=> $session['access_token'])); $targetPhoto = $FQLResult[0]; I tried to help a user of mine get their account back on track, however, re-authenticating the application seems like the only way to fix it. It works for most of the users, however, there are a couple few who get my exception message. If anyone has any knowledge of whats going on here, that would be appreciated I am able to connect to my AD server successfully. This server serves multiple domains. Example is user1@dom1.dom.net is able to successfully bind. user2@dom2.com is not able to bind but gets error 49: invalid credentials. Using windows ldp.exe, I can connect successfully, then select bind from the connection menu, enter the username (user2), the account password, and the Domain (dom2.com) and the result indicated is successful. Using php I attempt to bind using: $adBind = ldap_bind($ad, $adUname, $ldappass); Where $ad = successful connection resource, $adUname = user1@dom1.dom.com OR user2@dom2.com, $ldappass is the account password. As user1 it is successful, with user2 it is unable to bind with error 49. Any suggestions or help is greatly appreciated. Thanks in advance! can anyone see the problem here i am running php 5.3 on my server and GD seems to be enabled. and my host said it was probably something to do with the captcha files or script. <?php session_start(); /* * File: CaptchaSecurityImages.php * Author: Simon Jarvis * Copyright: 2006 Simon Jarvis * Date: 03/08/06 * Updated: 2007-08-12 by Jenny Ferenc (minor visual changes only) * Requirements: PHP 4/5 with GD and FreeType libraries * Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html * */ class CaptchaSecurityImages { var $font = 'VeraSe.ttf'; function generateCode($characters) { /* list all possible characters, similar looking characters and vowels have been removed */ $possible = '23456789bcdfghjkmnpqrstvwxyz'; $code = ''; $i = 0; while ($i < $characters) { $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1); $i++; } return $code; } function CaptchaSecurityImages($width=130, $height=40, $characters=6) { $code = $this->generateCode($characters); // font size will be 60% of the image height $font_size = $height * 0.6; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); // set the colours $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); // generate random dots in background for( $i=0; $i<($width*$height)/3; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } // generate random lines in background for( $i=0; $i<($width*$height)/150; $i++ ) { imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color); } // create textbox and add text $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function'); // output captcha image to browser header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $_SESSION['security_code'] = $code; } } $captcha = new CaptchaSecurityImages(); ?> this seems to be the problem line he Code: [Select] $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); [\code] My dad loves these frozen cheeseburgers from meijer so I was gonna write a little script I can run in cron that will check Meijer's website and txt or email or something if they go on sale. Whenever I run the below script I get an Access Denied response from the server instead of the html for the cheesburger page. I'm sure I just need a CURL option or something. Thank You in Advance
The dreadful apostrophie problem... This search form returns an error whenever searching with an apostrophie (') Here's the code on the form (html) <td align="center" width="135"><form method="post" action="srch_advert.php"><input type=text name='search' size=15 maxlength=255><br><input type=submit></form></td> <td align="center" width="135"><form method="post" action="srch_details.php"><input type=text name='search' size=15 maxlength=255><br><input type=submit></form></td> <td align="center" width="135"><form method="post" action="srch_artist.php"><input type=text name='search' size=15 maxlength=255><br><input type=submit></form></td> <td align="center" width="135"><form method="post" action="srch_track.php"><input type=text name='search' size=15 maxlength=255><br><input type=submit></form></td> and heres the code on srch_advert.php if ($search) // perform search only if a string was entered. { mysql_connect($host, $user, $pass) or die ("Problem connecting to Database"); $srch="%".$search."%"; $query = "select * from tvads WHERE advert LIKE '$srch' ORDER BY advert, year DESC, details ASC LIMIT 0,30"; $result = mysql_db_query("cookuk_pn", $query); if(mysql_num_rows($result)==0) { print "<h2>Your search returned 0 Results</h2>"; } else if ($result) { Here's the error: Code: [Select] Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/stayway1/public_html/www.one-mafia.com/eng/inboxread.php on line 99 Here's lines 90-110: (99 in bold) Code: [Select] if (strip_tags($_POST['Accept_OC'])){ $oc_id=strip_tags($_POST['oc_id']); if (strip_tags($_POST['place']) == "we"){ $use="we_inv"; $a="we"; $query= "SELECT * FROM oc WHERE we_inv='$username' AND id='$oc_id'"; }elseif (strip_tags($_POST['place']) == "ee"){ $use="ee_inv"; $a="ee"; $query= "SELECT * FROM oc WHERE ee_inv='$username' AND id='$oc_id'"; }elseif (strip_tags($_POST['place']) == "driver"){ $use="driver_inv"; $a="driver"; $query= "SELECT * FROM oc WHERE driver_inv='$username' AND id='$oc_id'"; } $round=mysql_query($query); [b]$check=mysql_num_rows($round);[/b] if ($check != "0"){ echo "You are now in that OC"; mysql_query("UPDATE `oc` SET `$a`='$username' WHERE `id`='$oc_id'"); mysql_query("UPDATE `users` SET `oc`='1' WHERE `username`='$username'"); } } if (strip_tags($_POST['Yes_street'])){ $race_id=strip_tags($_POST['race_id']); if ($fetch->street != "0"){ echo "Your in a race."; }elseif ($fetch->street == "0"){ if ($fetch->last_race >= time()){ echo "You cant do anouther race yet."; }elseif ($fetch->last_race < time()){ |