PHP - Mysql_num_rows Boolean Error?
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. Similar TutorialsThe 2 errors I am getting a Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\searchstock2.php on line 36 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\searchstock2.php on line 38 I am trying to search a table and return results, all fields are VARCHAR except ID (integer), here is part of my code; $link = mysql_connect("localhxxxxx","xxx",""); //(host, username, password) mysql_select_db("wadkin", $link) or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from stocklist where Stock Number like \'%$trimmed%\'OR Name like \'%$trimmed%\' OR Category like \'%$trimmed%\'"; if ($numresults=mysql_query($query)); $row = mysql_fetch_assoc($numresults); if ($row['COUNT(*)'] == 0); $numrows=mysql_num_rows($numresults); if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } // Determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["Name"]; echo "$count.) $title" ; $count++ ; } $row = mysql_fetch_assoc($numresults); = line 36 $numrows=mysql_num_rows($numresults); = line 38 Hi guys, I'm new to forums so hopefully someone can help me. I keep getting the following error: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Blog2\checklogin.php on line 27 My code is: Code: [Select] // Define $blog_user_name and $blog_user_password $blog_user_name=$_POST['blog_user_name']; $blog_user_password=$_POST['blog_user_password']; // To protect MySQL injection (more detail about MySQL injection) $blog_user_name = stripslashes($blog_user_name); $blog_user_password = stripslashes($blog_user_password); $blog_user_name = mysql_real_escape_string($blog_user_name); $blog_user_password = mysql_real_escape_string($blog_user_password); $sql="SELECT * FROM $tbl_name WHERE username='$blog_user_name' and password='$blog_user_password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); //THIS IS LINE 27 // If result matched $blog_user_name and $blog_user_password, table row must be 1 row if($count==1){ // Register $blog_user_name, $blog_user_password and redirect to file "index.php" session_register("blog_user_name"); session_register("blog_user_password"); header("location:index.php"); } else { echo "Wrong Username or Password"; } ob_end_flush(); Please can someone help I have know idea what the problem could be. Thanks. i give it up after 4 h. please help me, what i do wrong i am try to make a name, address search system into my website from my database. but i got this msg [Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampplite\htdocs\3\searchresult.php on line 54] my full php code i.e. searchresult.php is under...... what i have mistake..... searchresult.php <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php // TAKE THE INFORMATION FROM FORM. $search = $_GET['search']; // IF THERE IS NOT A KEYWORD GIVE A MISTAKE. if (!$search) echo "You didn't enter a keyword"; else { echo "<td>You searched for: <strong>$search </strong></td>"; mysql_connect('localhost','root',''); mysql_select_db('search'); $id=@$_GET['id']; //QUERY IS THE CODE WHICH WILL MAKE THE SEARCH IN YOUR DATABASE. //I WROTE AN EXPLANATION ABOUT IT AFTER THE CODE. $sql = "CREATE TABLE searchform \n" ."(\n" ."ID int NOT NULL AUTO_INCREMENT ,\n" ."FirstName varchar( 255 ) NOT NULL ,\n" ."LastName varchar( 255 ) NOT NULL ,\n" ."Email varchar( 255 ) NOT NULL ,\n" ."PhoneNumber varchar( 255 ) NOT NULL ,\n" ."PRIMARY KEY ( ID ) )";; $result1 = MySQL_query($query); if(!$result1) { echo MySQL_error()."<br>$query<br>"; } if(MySQL_num_rows($result1) > 5) { echo "<table width='750' align='center' border='0' cellspacing='0' cellpadding='0'>"; while($result2 = MySQL_fetch_array($result1)) { //A short description from category. $description = $result2['category']; $searchPosition = strpos($description, $search); $shortDescription = substr($description, $searchPosition, 150); // I added a link to results which will send the user to your display page. echo '<tr><td><p><strong><a href="displayresults.php?id='.$result2['id'].'">'.$result2['title'].'</strong></p></td></tr>'; echo "<tr><td>$shortDescription ...</td></tr>"; echo "<td>{$result2['name']} {$result2['surname']}</td><tr/>"; } echo "</table>"; }else { echo "No Results were found in this category.<br>"; }echo "<br>"; } ?> </body> </html> and searchform.php <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form action="searchresult.php" method="get"> <div align="center"> <p> <input name="search" type="text" size="60"/> <input name="submit" type="submit" value="Search" /> </p> </div> </form> </body> </html> 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! 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); 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........... Hi, I have an image uploader here and I am trying to have a user enter their password and check a box in order to submit their image. I am having trouble validating the password. I get this error message: "Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/68/6372768/html/submit.php on line 58" From this section of the code: $query = "SELECT * FROM user_info WHERE password = SHA($user_password)"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { $valid_password = true; } Anyone see what I am doing wrong? The password stored in my DB is encrypted with SHA. Code: [Select] <?php // Start the session require_once('startsession.php'); // Insert the page header $page_title = 'Submit an Image'; require_once('header.php'); require_once('appvars.php'); require_once('connectvars.php'); // Show the navigation menu require_once('navmenu.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<center><table border="0" cellspacing = "20"><tr><td>'; echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>'; echo '</td></tr></table></center>'; // Insert the page footer echo '<div class="footer">'; require_once('footer.php'); echo '</div>'; exit(); } ?> <div class="linkrow"> <!-- end .linkrow --></div> <div class="contentBlue960"> <img src = "/IMAGES/WEBSITE/capBlue960.jpg"> <?php if (isset($_POST['submit'])) { // Connect to the DB $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Set password to false $valid_password = false; // Grab the id data from the POST $image_name = $_FILES['image_name']['name']; $image_name_type = $_FILES['image_name']['type']; $image_name_size = $_FILES['image_name']['size']; $user_password = (mysqli_real_escape_string($dbc, trim($_POST['user_password']))); $agree = mysqli_real_escape_string($dbc, trim($_POST['agree'])); // Grab the id data from the DB if (!isset($_GET['user_id'])) { $query = "SELECT user_name, password FROM user_info WHERE user_id = '" . $_SESSION['user_id'] . "'"; } else { $query = "SELECT user_name, password FROM user_info WHERE user_id = '" . $_GET['user_id'] . "'"; } $data = mysqli_query($dbc, $query); $user_name = $row['user_name']; $password = $row['password']; $query = "SELECT * FROM user_info WHERE password = SHA($user_password)"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { $valid_password = true; } // If image and password are entered if (!empty($user_password) && !empty($image_name)) { // If the entered password matches the user's password if ($valid_password == true) { // If the copyright is agreed to if (($agree) == ('checked')) { // If the pic is valid if ((($image_name_type == 'image/gif') || ($image_name_type == 'image/jpeg') || ($image_name_type == 'image/pjpeg') || ($image_name_type == 'image/png')) && ($image_name_size > 0) && ($image_name_size <= GW_MAXFILESIZE)) { if ($_FILES['image_name']['error'] == 0) { // Move the file to the target upload folder $target = GW_UPLOADPATH . $image_name; if (move_uploaded_file($_FILES['image_name']['tmp_name'], $target)) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); // Write the data to the database $query = "INSERT INTO user_images VALUES (0, '$user_name', NOW(), '$image_name')"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>Thanks for submitting an image! Under review as soon as possible.</p>'; echo '<p><strong>User Name:</strong> ' . $user_name . '<br />'; echo '<img src="' . GW_UPLOADPATH . $image_name . '" alt="Submitted Image" /></p>'; echo '<p><a href="submit.php"><< Back to submit page.</a></p>'; // Clear the id data to clear the form $user_name = ""; $image_name = ""; mysqli_close($dbc); } else { echo '<p class="error">Sorry, there was a problem uploading your screen shot image.</p>'; } } } else { echo '<p class="error">The screen shot must be a GIF, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size.</p>'; } // Try to delete the temporary screen shot image file @unlink($_FILES['image_name']['tmp_name']); } else { echo '<p class="error">Must agree with and check copyright box.</p>'; } } else { echo '<p class="error">Password Incorrect</p>'; } } else { // echo 'Pass' . $password . ' 1'; // echo 'User pass' . $user_password . ' 2'; // echo 'Checkbox' . $agree . ' 3'; // echo 'Username' . $user_name . ' 3'; echo '<p class="error">Please enter all of the information to add your image.</p>'; } } // mysqli_close($dbc); ?> <table border="1" cellspacing = "20"> <tr><td width = 960px><h2>Submit an Image</h2></td></tr> </table> <table border="1" cellspacing = "20"> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <tr><td width = "300"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo GW_MAXFILESIZE; ?>" /> <label for="image_name">Image:</label></td> <td><input type="file" id="image_name" name="image_name" /> </td></tr> <tr><td width = "300"> <label for="user_password">Enter Password:</label></td> <td><input type="text" id="user_password" name="user_password" /><br /> </td></tr> <tr><td width = "300"> <label for="terms">This image is my own work and I own all copyrights to it.</label></td> <td><input type="checkbox" id="agree" name="agree" value = "checked"/><br /> </td></tr> <tr><td width = "300"> <input type="submit" value="Submit Image" name="submit" /> </td></tr> </form> </td> </tr> </table> <img src = "/IMAGES/WEBSITE/bottomBlue960.jpg"> <!-- end .contentWhite960 --></div> <div class="footer"> <?php // Insert the page footer require_once('footer.php'); ?> <!-- end .footer --></div> Thanks if you can help, Craig why does the top code work and the bottom does not? what am i missing? the only real diffrence is the query. im getting "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in " for this code $numrows = mysql_num_rows($result). the query works fine in phpmyadmin. thanks $query = "SELECT * FROM dsgi_servlist " ; $result = mysql_query($query) ; $numrows = mysql_num_rows($result) ; echo $numrows ; $sql = "SELECT COUNT(*) FROM dsgi_servlist where location = 'hdd'"; $result = mysql_query($sql) ; $numrows = mysql_num_rows($result) ; echo $numrows ; I created this function to update my tour system. The query is working and is updating one row in the table, but I get a resource boolean error in the return section of the function. Any idea why? Code: [Select] function update_tour($uid, $step) { $step = (int)$step; $uid = (int)$uid; $sql = "UPDATE `users` SET `tour_step` = ${step} WHERE `id` = '${uid}'"; $q = mysql_query($sql) or die(mysql_error()); return (mysql_num_rows($q) === 1) ? mysql_result($q, 0): false; } 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>'; 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. 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? why is this code not working? in php i have the following...
$keywords = "+hello +world"; $query= "SELECT * FROM forums WHERE MATCH (topics) AGAINST ('$keywords' IN BOOLEAN MODE)"; $results = mysqli_query($database, $query); $row = mysqli_fetch_assoc($results); $topics = $row['topics']; echo $topics; Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given... Hey, I found some code online that references a bunch of sql commands in there own functions that can be called from a require_once(), All the ones I have tried work expect mysql_query when its called it returns this error: Quote Warning: mysql_result() expects parameter 1 to be resource, boolean given in But once i paste the mysql_query into the main script it works fines. code below is mine and the online script. Webcode: Code: [Select] $sql = "SELECT cat_id, cat_parent_id, cat_name, cat_description, cat_image FROM tbl_category WHERE cat_parent_id = $catId ORDER BY cat_name"; /* Don't know what getPagingQuery does and couldnt find any reference to it so i removed it and replaced with simple query in my own code */ $result = dbQuery(getPagingQuery($sql, $rowsPerPage)); My Code: Code: [Select] $sql = "SELECT cat_id, cat_parent_id, cat_name, cat_description, cat_image FROM tbl_category WHERE cat_parent_id = $catId ORDER BY cat_name"; $result = dbQuery($sql); Include file: Code: [Select] $dbHost = "localhost"; //SQL Server $dbUser = "root"; // Database username $dbPass = ""; // Database password $dbName = "lh_shop"; // Database name $sqlCon = mysql_connect($dbHost, $dbUser, $dbPass) or die ('MYSQL connection Failed. ' . mysql_error()); mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error()); // Database query functions function dbQuery($sql) { return mysql_query($sql) or die('Query failed. ' . mysql_error()); } Thanks, I really hope someone has had this issue This is a new error for me. I tried looking through some older posts and so far nothing had fixed it and thus I am stumped. Any idea what could be throwing this error? Code: [Select] <table> <?php //open DB connection include 'dbconn.php'; $sql = "select * tbl_test"; $result = mysql_query($sql,$conn); print $sql; while ($row = mysql_fetch_array($result)){ $status = $row['status']; $space = $row['spacename']; if ($status=="reserved") { echo <<<END <tr> <td style="background-color:#F00; color:#FFF;" align="center">Reserved</td> </tr> END; } else { echo <<<END <tr> <td align="center">$space</td> </tr> END; } } ?> </table> |