PHP - Warning: Mysql_num_rows(): Supplied Argument Is Not A Valid Mysql Result Resourc
Hi, I am having an issue with a piece of code. I am getting the following error, any ideas please?
Quote Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ... Code: [Select] <?php include "scripts/connect.php"; $last = $_GET['ref']; // This will be the ID of the page echo "the ref number is $last"; $query = mysql_query("SELECT * FROM news WHERE `ref` = '$last'"); if(mysql_num_rows($query)==0){ die("Something went wrong, contact Administrator!"); }else{ while($info = mysql_fetch_array($query)){ $title = $info ['title']; echo "<p><a href=\"..news.php\" target=\"_blank\">$title >></a></p>"; } } ?> Similar TutorialsHi, After moving server my script started showing this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/user/public_html/blog.php on line 107 Here is the code on line 107: if(mysql_num_rows($ExeqryComm)!=0){ Any help please? Thank you all Hi all, complete newbie here. i have copied this example php code to insert data and a picture into a mysql database. however i get this error. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource can be seen here : http://wycombedjs.co.uk/mix/sqltest.php Any help would be much appreciated.. thanks Code: [Select] <?php $db_host = 'xxx'; // don't forget to change $db_user = 'xxx'; $db_pwd = 'xxx'; $database = 'mixdb'; $table = 'ae_gallery'; // use the same name as SQL table $password = '123'; // simple upload restriction, // to disallow uploading to everyone if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // This function makes usage of // $_GET, $_POST, etc... variables // completly safe in SQL queries function sql_safe($s) { if (get_magic_quotes_gpc()) $s = stripslashes($s); return mysql_real_escape_string($s); } // If user pressed submit in one of the forms if ($_SERVER['REQUEST_METHOD'] == 'POST') { // cleaning title field $title = trim(sql_safe($_POST['title'])); if ($title == '') // if title is not set $title = '(empty title)';// use (empty title) string if ($_POST['password'] != $password) // cheking passwors $msg = 'Error: wrong upload password'; else { if (isset($_FILES['photo'])) { @list(, , $imtype, ) = getimagesize($_FILES['photo']['tmp_name']); // Get image type. // We use @ to omit errors if ($imtype == 3) // cheking image type $ext="png"; // to use it later in HTTP headers elseif ($imtype == 2) $ext="jpeg"; elseif ($imtype == 1) $ext="gif"; else $msg = 'Error: unknown file format, .png, .jpeg, .gif only!'; if (!isset($msg)) // If there was no error { $data = file_get_contents($_FILES['photo']['tmp_name']); $data = mysql_real_escape_string($data); // Preparing data to be used in MySQL query mysql_query("INSERT INTO {$table} SET ext='$ext', title='$title', data='$data'"); $msg = 'Success: image uploaded to Mix db'; } } elseif (isset($_GET['title'])) // isset(..title) needed $msg = 'Error: file not loaded';// to make sure we've using // upload form, not form // for deletion if (isset($_POST['del'])) // If used selected some photo to delete { // in 'uploaded images form'; $id = intval($_POST['del']); mysql_query("DELETE FROM {$table} WHERE id=$id"); $msg = 'Photo deleted'; } } } elseif (isset($_GET['show'])) { $id = intval($_GET['show']); $result = mysql_query("SELECT ext, UNIX_TIMESTAMP(image_time), data FROM {$table} WHERE id=$id LIMIT 1"); if (mysql_num_rows($result) == 0) die('no image'); list($ext, $image_time, $data) = mysql_fetch_row($result); $send_304 = false; if (php_sapi_name() == 'apache') { // if our web server is apache // we get check HTTP // If-Modified-Since header // and do not send image // if there is a cached version $ar = apache_request_headers(); if (isset($ar['If-Modified-Since']) && // If-Modified-Since should exists ($ar['If-Modified-Since'] != '') && // not empty (strtotime($ar['If-Modified-Since']) >= $image_time)) // and grater than $send_304 = true; // image_time } if ($send_304) { // Sending 304 response to browser // "Browser, your cached version of image is OK // we're not sending anything new to you" header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ts).' GMT', true, 304); exit(); // bye-bye } // outputing Last-Modified header header('Last-Modified: '.gmdate('D, d M Y H:i:s', $image_time).' GMT', true, 200); // Set expiration time +1 year // We do not have any photo re-uploading // so, browser may cache this photo for quite a long time header('Expires: '.gmdate('D, d M Y H:i:s', $image_time + 86400*365).' GMT', true, 200); // outputing HTTP headers header('Content-Length: '.strlen($data)); header("Content-type: image/{$ext}"); // outputing image echo $data; exit(); } ?> <html><head> <title>MySQL Blob Image Gallery Example</title> </head> <body> <?php if (isset($msg)) // this is special section for // outputing message { ?> <p style="font-weight: bold;"><?=$msg?> <br> <a href="<?=$PHP_SELF?>">reload page</a> <!-- I've added reloading link, because refreshing POST queries is not good idea --> </p> <?php } ?> <h1>Blob image gallery</h1> <h2>Uploaded images:</h2> <form action="<?=$PHP_SELF?>" method="post"> <!-- This form is used for image deletion --> <?php $result = mysql_query("SELECT id, image_time, title FROM {$table} ORDER BY id DESC"); if (mysql_num_rows($result) == 0) // table is empty echo '<ul><li>No images loaded</li></ul>'; else { echo '<ul>'; while(list($id, $image_time, $title) = mysql_fetch_row($result)) { // outputing list echo "<li><input type='radio' name='del' value='{$id}'>"; echo "<a href='{$PHP_SELF}?show={$id}'>{$title}</a> – "; echo "<small>{$image_time}</small></li>"; } echo '</ul>'; echo '<label for="password">Password:</label><br>'; echo '<input type="password" name="password" id="password"><br><br>'; echo '<input type="submit" value="Delete selected">'; } ?> </form> <h2>Upload new image:</h2> <form action="<?=$PHP_SELF?>" method="POST" enctype="multipart/form-data"> <label for="title">Title:</label><br> <input type="text" name="title" id="title" size="64"><br><br> <label for="photo">Photo:</label><br> <input type="file" name="photo" id="photo"><br><br> <label for="password">Password:</label><br> <input type="password" name="password" id="password"><br><br> <input type="submit" value="upload"> </form> </body> </html> some please help - basically have a simple password change php page $sql="UPDATE t_members SET Password = '$New_Password' WHERE Username = '$My_Username' AND Password = '$Old_Password'"; echo $sql; $result=mysql_query($sql) or die(mysql_error()); $firstcount = mysql_num_rows($result); and i get this annoying error Warning: mysql_num_rows(): supplied argument is not a valid the sql statement works as i see it updating the database correctly Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 14. <?PHP require_once("dbcheck.php"); require_once("check.php"); $Username=$_COOKIE['Username']; $Password=$_COOKIE['Password']; $Nickname=$_COOKIE['Nickname']; $Username=mysql_real_escape_string($Username); $Password=mysql_real_escape_string($Password); date_default_timezone_set('Asia/Calcutta'); $action = $_GET['do']; $Result=mysql_query("SELECT * FROM Checks WHERE UserName='$Username'"); $Rowexist=mysql_num_rows($Result); if($Rowexist!=0){ while($Rows=mysql_fetch_array($Result)) { $Serial = $Rows['Serial']; $Banned = $Rows['Banned']; $IP = $Rows['IP']; $Used = $Rows['Used']; $First = $Rows['First']; $Duration = $Rows['Duration']; $Total = $Rows['Total']; $Time = $Rows['Time']; } if($action=="" || $action=="Banlist"){ mysql_query("UPDATE Checks SET NickName='$Nickname' WHERE UserName='$Username'"); ?> Hi everyone! I have the following error message: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hermes/bosweb25a/b109/ipg.removalspacecom/checklogin.php on line 47 Wrong Username or Password by using the below code: Code: [Select] <?PHP include ('db.php'); // Define $username and $password $username=$_POST['username']; $password=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM $companies WHERE username='$username' and password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if($count==1){ // Register $username, $password and redirect to file "login_success.php" session_register("username"); session_register("password"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> Does anyone have an idea of whats happening? from a guess it's looking for the username and password in the database, but i've made sure that this username and password in IN the correct fields in the table ect?? Thanks Hi guys, I have this code here working which will show certain data in the table depending on what string the user searches for, and with the records that pop up you are able to delete these records too.. now all this is working but after I delete records I get this error: "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/define/public_html/golf/Pete/php/searchcallback.php on line 22" I assume this is because num rows are empty after the deletion is done/ and this now shows "no records showing" can anyone help me why this error is popping up? Although deletion does work, I would like to get rid of this error message. Code: [Select] <?php include "connect.php"; $searchvalue = $_POST['searchvalue']; $su = $_POST['search']; //Check if records were submitted for deletion if(isset($_POST['callbackid']) && count($_POST['callbackid'])) { //Ensure values are ints $deleteIDs = implode(', ', array_map('intval', $_POST['callbackid'])); $query = "DELETE FROM callback WHERE callbackid IN ({$deleteIDs})"; //Debug line echo "<br/>Successfuly deleted callback(s) <br/>"; mysql_query($query) or die(mysql_error()); } $result = mysql_query("SELECT * FROM callback WHERE $searchvalue LIKE '%$su%'"); $num_rows = mysql_num_rows($result); ?> <link rel="stylesheet" type="text/css" href="view.css" media="all"> <script type="text/javascript" src="view.js"></script> <body id="main_body" > <img id="top" src="top.png" alt=""> <div id="form_container"> <h1>Show, Search or Delete Callback Records<</h1> <form id="form_362567" class="appnitro" method="post" action="searchcallback.php"> <div class="form_description"> <h2> Show, Search or Delete Callback Records</h2> <p></p> </div> <ul > <li class="section_break"> <?php if ($num_rows==0){ ?> <br>No records found<br><br> <INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1);return true;"><br> <?php } else{ while($row = mysql_fetch_array($result)) { //..results as in your post. echo "<form action='' method='POST'>"; echo "<br/>"; echo "<b>Callback ID:</b>"; echo "<br/>"; echo $row['callbackid']; echo "<br/>"; echo "<b>Full Name:</b>"; echo "<br/>"; echo $row['fullname']; echo "<br/>"; echo "<b>E-mail:</b>"; echo "<br/>"; echo $row['email']; echo "<br/>"; echo "<b>Phone Number:</b>"; echo "<br/>"; echo $row['phone']; echo "<br/>"; echo "<b>Comment:</b>"; echo "<br/>"; echo $row['comment']; echo "<br/>"; echo "<input type='checkbox' name='callbackid[]' value='{$row['callbackid']}' /> <b>Delete</b>\n"; ?> <li class="section_break"> <?php } ?> <br><input type='submit' value='Delete Records' name='delete' /><INPUT TYPE="button" VALUE="Cancel" onClick="history.go(-1);return true;"><br> </form> <div id="footer"> </div> </div> <img id="bottom" src="bottom.png" alt=""> </body> <?php } ?> Thanks for any help in advance I get the following error: with the following code: Code: [Select] $username="****"; $password="****"; $database="checkmyw_database"; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query3="SELECT * FROM hours WHERE (out1<>'0' AND in1=='0' OR out2<>'0' AND in2=='0') && (date==$date)"; $result3=mysql_query($query3); $num3=mysql_numrows($result3); mysql_close(); if($num3==0){ $clockedout="true";} echo $clockedout; Any ideas why I am simply trying to display the last 8 images from a mysql database and i am getting this error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/aretheyh/public_html/nealeweb.com/gnew2/recent.php on line 8 Can somebody please tell me what i am doing wrong. Code: [Select] <?php $i = 1; echo '<table border="0" cellpadding="0" cellspacing="0"> <tr>'; include("config.inc.php"); $result = mysql_query("SELECT * FROM gallery_photos ORDER BY id DESC LIMIT 8"); while($row = mysql_fetch_assoc($result)) { // Start of the loop $img = $row['".$images_dir."/tb_']; echo "<td><img src=$img></td>"; if ($i == 4) { echo '</tr><tr>'; } $i++; } echo '</tr></table>'; Hi, I am having problem with mysql and php.... when i test the database on my local host it didt produce any error but when i put it on my web host it gave me error messages... "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource" Please help me as i am new to php. Quote <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="http://www.hingloong.com/pricesearch/style.css" /> <title>Price Search Query</title> </head> <body> <form method=GET action="search.php"> <div id=container> <select name=general> <option value = all>Select</option> <option value = laptop>Laptop</option> <option value = mobile>Mobile</option> <option value = games>Games</option> <option value = camera>Camera</option> </select> <label><b>Brand:</b></label> <input type=text name=brand> <label><b>Model:</b></label> <input type=text name=model> <input type=submit name=search value=Search> </form> <br><br> <input type=button name=gamelist value=View Games onclick="location.href='gamelist.php'"> <input type=button name=mobilelist value=View Mobile onclick="location.href='mobilelist.php'"> <input type=button name=cameralist value=View Cameras onclick="location.href='cameralist.php'"> <input type=button name=laptoplist value=View Laptops onclick="location.href='laptoplist.php'"> </div> </body> </html> <?php include ("connect.php"); $general = $_GET['general']; $brand = $_GET['brand']; $model = $_GET['model']; if($general == 'mobile') { echo "<br>"; echo "<h3>Mobile Phone Prices</h3>"; echo "<div id=container>"; echo "<table>"; echo "<tr>"; echo "<td class=head>Phone Brand</td>"; echo "<td class=head>Phone Model</td>"; echo "<td class=head>Phone Loan</td>"; echo "<td class=head>Phone Buy</td>"; echo "<td class=head>Phone Sell</td>"; echo "<td class=head>Phone Rrp</td>"; echo "</tr>"; $query = "select * from mobilephones where phone_brand LIKE ('$brand%') AND phone_model LIKE ('$model%') "; $temp = mysql_query($query) or die(mysql_error()); } while ($row = mysql_fetch_array($temp)) { echo "<tr>"; echo "<td>" .$row['phone_brand']. "</td>"; echo "<td>" .$row['phone_model']. "</td>"; echo "<td>" .$row['phone_loan']. "</td>"; echo "<td>" .$row['phone_buy']. "</td>"; echo "<td>" .$row['phone_sell']. "</td>"; echo "<td>" .$row['phone_rrp']. "</td>"; } echo "</table>"; echo "</div>"; ?> Hi, first post, and yes it is a question. I am stuck, and not by choice, this error has given me more headaches than I care to admit. I have a script that I am attempting here, that is very simple for now, all I want to show is the Added_By field to show it is accessing the database correctly and the right row/line all together. The page to test this at is he http://kaboomlabs.com/PDI/@dm!n/viewncmr.php?id=2 The Error is this: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pawz/public_html/kaboomlabs.com/PDI/@dm!n/viewncmr.php on line 18 This is row 18: $row = mysql_fetch_array($data); Now I know this is not a secure form yet, I am working on getting the basic functions down then I'll secure it, so please let me worry about that when the time comes. Here is the script, can anyone see a blatant issue or not? Thanks in advance. Code: [Select] <?php require_once('../connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '" . $_SESSION['id'] . "'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; $data = mysqli_query($dbc, $query); } if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysql_fetch_array($data); echo '<fieldset>'; if (!empty($row['Added_By'])) { echo '<div id ="added"><label>Added By:</label>' . $row['Added_By'] . '</div></fieldset>'; } } // End of check for a single row of user results else { echo '<p class="error">There was a problem accessing your profile.</p>'; } mysqli_close($dbc); ?> Hi guys, for the life of me, what am I doing wrong, I cannot figure out this one, getting this error : Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ......... search.php on line 36 my code : Code: [Select] $start = ($page-1)*$per_page; $sql = "SELECT productId, productCode, image, name, price, stock_level FROM inventory WHERE productCode LIKE '%".$searchp."%' OR name LIKE '%".$searchp."%' AND Seller_ID = '" . $_SESSION['SESS_SELL_ID'] . "' order by name limit $start,$per_page"; $rsd = mysql_query($sql); <?php while($row = mysql_fetch_array($rsd)) // ERROR OCCURS HERE : line 36 { $idpc=$row['productId']; $idc=$row['productCode']; $idi=$row['image']; $idn=$row['name']; $idp=$row['price']; $ids=$row['stock_level']; ?> all help appreciated as always. In the following code, at the mysql query immediately following the <!--end accordianButton div-->, Some of the rows will echo out the content, while some of the rows will throw the Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... error. Any idea why? Go here to see what I mean: http://www.chalmerscommunitychurch.com/P2P_archives.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=utf-8" /> <title>Pastor to People Blog Archives</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"> </script> <script type="text/javascript" src="js/javascript.js"> </script> <style> .accordionButton { width: 100%; height:30px; float: left; background: url(../images/button.png); border-bottom: 1px solid #FFFFFF; cursor: pointer; } .accordionContent { width: 100%; float: left; display: none; } </style> </head> <body> <?php require("include.php"); $con = mysql_connect("$db_host","$db_username","$db_pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("chalmers_db", $con); $result = mysql_query("SELECT title, date FROM blog"); while($row = mysql_fetch_array($result)) { $title=$row['title']; $sqldate=$row['date']; $date=date('m-d-Y',strtotime($sqldate)); ?> <!--start accordionButton div--> <div class="accordionButton"><?php echo $title;?>, <?php echo $date;?> </div> <!--end accordianButton div--> <?php $query = mysql_query("SELECT content FROM blog WHERE title = '".$title."' ORDER BY date DESC"); while ($row = mysql_fetch_array($query)){ $content = $row['content']; ?> <!--start accordionContent div--> <div class="accordionContent" align="justify"> <?php echo $content;?> </div> <!--end accordionContent div--> <?php } ?> <?php } ?> <p><p><p><p><a href="http://www.chalmerscommunitychurch.com"><h3>Back to Chalmers Community Church</h3></a> </body> </html> $getURL = mysql_fetch_assoc(mysql_query("SELECT `urlname` FROM `workingurls` ORDER BY RAND() LIMIT 1")); spits out Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /public_html/script.php on line 130 How do you make mysql_fetch_assoc a valid MySQL result resource? I am getting an error message. Quote mysql_fetch_array(): supplied argument is not a valid MySQL result My Sql seems to work fine. But I kept on getting this error message whenever I try to view orderid. I have option to view different field such as orderid, orderdate, price and profit. When the page loads its fine. But when I try to view orderdate the orderid I get the error message Error code is on the first line and the other places where it says $result. Code: [Select] while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td align='left'>" . $row['orderid'] . "</td>"; echo "<td align='left' style='font-size:12px;'>" . $row['orderdate'] . "</td>"; echo "<td align='left' style='font-size:12px;'>" . $row['updated'] . "</td>"; echo "<td align='left' style='font-size:12px;'>" . $row['name'] . "</td>"; echo "<td align='left' style='font-size:12px;'>" . $row['price'] . "</td>"; echo "<td align='left'>" . $row['salesman'] . "</td>"; echo "<td align='left'>" . $row['origsalesman'] . "</td>"; echo "<td align='left'>" . $row['status'] . "</td>"; echo "<td align='left'>" . $row['product'] . "</td>"; echo "<td align='left'>£" . $row['profit'] . "</td>"; echo "</tr>"; echo "<tr><td colspan='10'><hr></td></tr>"; } if ( mysql_num_rows( $result ) == 0 ) echo "<tr><td colspan='10'>No orders found<hr></td></tr>"; echo "</table></form>"; mysql_free_result( $result );code] Please help me. Thanks for reading! I'm working on a site and it won't display my records from the database. I have a little filter system that did work, but now it doesn't. I get the following error message: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/60608.glrdmd.eu/httpdocs/jakesite/select3.php on line 26 Relevant code to the error is: Code: [Select] <?php include("connection.php"); if(isset($_POST['Graphic']) && $_POST['Graphic'] == 'yes') { $result1 = "graphic"; } if(isset($_POST['Interactive']) && $_POST['Interactive'] == 'yes') { $result2 = "interactive"; } if(isset($_POST['Websites']) && $_POST['Websites'] == 'yes') { $result3 = "websites"; } $order = $_POST['group1']; $sql = ("SELECT * FROM 'jake_portfolio' WHERE CAT = '$result1' OR CAT = '$result2' OR CAT = '$result3' ORDER BY '$order' LIMIT 0, 4"); $result = mysql_query($sql); $checked = "checked"; $row = mysql_fetch_array($result); ?> Does anyone see what I am doing wrong here? I have a function that generates a random number and checks to make sure it does not exists in the database. I call this function using Code: [Select] $ref = get_record_ref(); I get the following error. Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in line 68 EDITED.... if i place the code from the function in my script and not use it as a function the script works. why would this be? Code: [Select] <?php db_connect() or die('Unable to connect to database server!'); function db_connect($server = 'localhost', $username = 'username', $password = 'password', $database = 'databasename', $link = 'db_link') { global $$link; $$link = mysql_connect($server, $username, $password); if ($$link) mysql_select_db($database); return $$link; } //Function to handle database errors. function db_error($query, $errno, $error) { die('<font color="#000000"><strong>' . $errno . '<br><br><br><br><small><font color="#ff0000">[STOP]</font></small><br><br></strong><br><br><br>One of our coders have been informed of this problem and shall be working on it very shortly.<br><br>Please try again in a few minutes or so when we should have this issue fixed.<br><br>Thank you.</font>'); } //Function to query the database. function db_query($query, $link = 'db_link') { global $$link; $theip = $_SERVER['REMOTE_ADDR']; $httpuseragent = $_SERVER['HTTP_USER_AGENT']; $fromlink4 = gethostbyaddr($_SERVER['REMOTE_ADDR']); // this next line is the error line 68 $result = mysql_query($query, $$link) or db_error($query, mysql_errno(), mysql_error()); return $result; } function get_record_ref() { // /* // set new $record_ref. $record_ref = (rand(10, rand(10, 1000000000))); // check if exisits in DB. $sql = "SELECT * FROM `table` WHERE `record_ref` = '". $record_ref ."'"; $get_records_with_record_ref = db_query($sql,''); // count entries in DB for $record_ref. $count_record_ref = mysql_num_rows($get_records_with_record_ref); while ($count_record_ref > 0) { // set new $record_ref. $record_ref = (rand(10, rand(10, 1000000000))); // check if exisits in DB. $sql = "SELECT * FROM `table` WHERE `record_ref` = '". $record_ref ."'"; $get_records_with_record_ref = db_query($sql); // count entries in DB for $record_ref. $count_record_ref = mysql_num_rows($get_records_with_record_ref); } // */ return $record_ref; } ?> This is the full error...Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in This is what I am trying to do... 1. get data from the page before which it gets fine in the $_GET function... 2. then set the sersion[username] to $username...(I think I am doing something wrong there) 3. then if the $username doesnt match the username pulled from the database (according to the $_GET info) then open a different databse and update a value in that table. 4. then kill the code die (); someone please help I have been trying to figure this out all day Code: [Select] <?php $username = $_SESSION['username']; $deleted = $_GET['deleted']; // Connect to MySQL $connect = mysql_connect("db","user","pass") or die("Not connected"); mysql_select_db("dv") or die("could not log in"); // grab the information according to the isbn number $query = "SELECT * FROM 'boox' WHERE isbn='$deleted'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { if ($username==$row['username']) { echo"Welcome, ".$_SESSION['username'].""; // Delete entry where isbn number matches accordingly mysql_query("DELETE * FROM 'boox' WHERE isbn='$deleted'"); } elseif ($username!=$row['username']) { $username = $_SESSION['username']; $connect = mysql_connect("db","user","pass") or die("Not connected"); mysql_select_db("db") or die("could not log in"); // run a query to deactivete a account $acti = mysql_query("UPDATE 'desiredusers' SET activated='2' WHERE username='$username'"); $byebye = "SELECT * FROM 'desiredusers' WHERE isbn='$deleted'"; $results = mysql_query($byebye); while($row2 = mysql_fetch_array($results)) echo "here".$username."here"; die("Your account is deactivated contact College Boox Store to get your account back."); } else echo "there is nothing being checked" . $username . ""; } ?> Hi Guys, I have been working on a recursive select box that will allow sub-categories and keep getting the error: <b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>test.php</b> on line <b>22</b><br / i have a table as follows: Code: [Select] CREATE TABLE IF NOT EXISTS `ost_help_topic` ( `topic_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `isactive` tinyint(1) unsigned NOT NULL DEFAULT '1', `noautoresp` tinyint(3) unsigned NOT NULL DEFAULT '0', `priority_id` tinyint(3) unsigned NOT NULL DEFAULT '0', `dept_id` tinyint(3) unsigned NOT NULL DEFAULT '0', `CatParent` bigint(11) unsigned DEFAULT NULL, `topic` varchar(32) NOT NULL DEFAULT '', `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`topic_id`), UNIQUE KEY `topic` (`topic`), KEY `priority_id` (`priority_id`), KEY `dept_id` (`dept_id`) ) Code: [Select] <?php $db_host = "localhost"; $db_un = "user"; $db_pass = "pass"; $Item_DB = "data"; $table = "ost_help_topic"; $link = mysql_connect($db_host, $db_un, $db_pass); $tab = " "; // this is 8 spaces, which works as a pseudo-tab character inside the <option>s $tablvl = 1; function print_kids($pos) { // $pos is the current position inside the hierarchy (curr item's ID) global $link; global $tab; global $tablvl; $pos = ($pos?$pos:null); $query = "SELECT * from $table WHERE isactive=1 AND CatParent".($pos == null ? " IS NULL" : "=".$pos); // NULL parent == top level item. For 0-parents, replace " IS NULL" with "=0" $res = mysql_db_query($Item_DB, $query, $link); if (!$res) print(mysql_error()); while($row = mysql_fetch_array($res)) { $has_kids = mysql_fetch_array(mysql_db_query($Item_DB, "SELECT * from $table where isactive=1 AND CatParent=$row[0]", $link)) != null; print("<option value=\"$row[0]\">"); for ($i=0; $i<$tablvl; $i++) print($tab); print("$row[6]</option>\n"); if ($has_kids) { $tablvl++; print_kids($row[0]); // <span class="posthilit">recursive</span> call $tablvl--; } } } $numrows = 1; $res = mysql_db_query($Item_DB, "SELECT * FROM $table", $link); while (mysql_fetch_array($res)) $numrows++; // Yes, I'm sure there's a more efficient way to do this <img src="./images/smilies/icon_razz.gif" alt=":P" title="Razz" /> print("<select name=\"hierarchy\" size=\"$numrows\">\n"); print("<option value=\"null\" selected=\"selected\">Root of all items</option>\n"); print_kids(0); print("</select>"); mysql_close($link); ?> |