PHP - Resource Id #35 Error?
I am currently trying create a sales system where it checks the user's username against the database to check whether they are in the list of buyers.
The mysql query returns "Resource id #35", I need it to return the actual username (which I manually inserted into the database to test). PHP code that fetches from database: <?php $con = mysql_connect("x","x","x"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("x", $con); $check_buyer = "SELECT * FROM Buyers WHERE Buyer='x'"; $buyer = mysql_query($check_buyer); ?> Product page: <?php include("/home/x/public_html/scripts/buyer.php"); if ($user->data['user_id'] == ANONYMOUS) { echo 'To use ' . $product . 'you must be logged in!'; echo '<br /><a href="http://x/forum/ucp.php?mode=register">Register</a>'; echo ' or '; echo '<a href="http://x/forum/ucp.php?mode=login">Sign In</a>'; } elseif ($user->data['username_clean'] == $buyer) { echo "<h3>Welcome to x</h3>"; } else { echo "You need to buy this product to use it!"; echo $user->data['username_clean']; //test whether username is outputted correctly - which it did echo $buyer; //Fetched from mysql - returned "Resource id #35", not the desired username } ?> Any help would be great! Thanks, otester Similar TutorialsHi, I have the following code which I have been able to put together with alot of the brilliant help on this forum. When I run this code it just came up with a blank screen and the CSS however I added another error print "echo "fetchdata: $fetchdata<br>Failed with error: " . mysql_error() . '<br>';" and the result now is "fetchdata: Resource id #2". However, when search for this on Google many of the responses data back from between 2002-2006. Does it just mean that there is an error with the second if query or does Resource id #2 refer to a specific error? Im really puzzled why I cant find anything more modern to this error on Google. <?php if( isset($_GET['id']) && ctype_digit($_GET['id']) ) { // validate that $_GET['id'] is set, and contains only numeric characters $id = (int) $_GET['id']; // cast value as an integer, and assign to $id $query = "SELECT * FROM productfeed WHERE id = $id"; if( !$fetchdata = mysql_query($query) ) { // numeric values shouldn't be quoted in query strings. echo "query: $query<br>Failed with error: " . mysql_error() . '<br>'; } else { while($row = mysql_fetch_array($fetchdata)) $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class=\"productdisplayshell\"> <div class=\"productdisplayoutline\"> <div class=\"productborder\"><center> <a href=\"$link\" target=\"_blank\" ><img src=\"$image\" /></a> </center> </div></div> <div class=\"productdescriptionoutline\"><div class=\"productdescriptionbox\"> <a href=\"$link\" target=\"_blank\" >$description</a> </div><div class=\"productfulldescriptionbox\"> $fulldescription </div></div> <div class=\"productpriceoutline\"> <div class=\"productpricebox\"><center>&#163; $price</center></div> <div class=\"productbuybutton\"><center><a href=\"$link\" target=\"_blank\" ><img src=/images/buybutton.png /></a></center></div></div></div>"; echo "fetchdata: $fetchdata<br>Failed with error: " . mysql_error() . '<br>'; } } else { echo 'Product is not available. Please visit our <a href="http://www.ukhomefurniture.co.uk">Homepage</a>'; exit(); } ?> 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; } I keep getting this error when I run the following code: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\vitamin-k-tracker\my-meal-planner.php on line 29 Code: [Select] <?php include 'top.php'; ?> <?php if (!loggedin()) {//1 if start header('Location: need-to-log-in-mmp.php'); }//1 if end ?> <title>My Meal Planner - Vitamin K Tracker</title> </head> <div id="container"> <?php include 'header.php'; ?> <?php include 'nav.php'; ?> <?php //do sql query to return the foods and nutrients that a person added to their que // // we're doing a left join between the foods and user foods table connected by the id $queryc = "SELECT `foods.id`, `foods.name`, `foods.source`, `users_foods.food_id` FROM `foods` LEFT JOIN users_foods ON foods.id=users_foods.food_id"; $query_runc = mysql_query($queryc); //error on the line below: while ($rowc = mysql_fetch_array($query_runc)){ echo 'ok'; } ?> <div id="content-container"> <div id="content_for_site"> <h2>My Meal Planner</h2> <br /> My Meal Que: <br /> <ul> <form> <li><input type="checkbox" name="meal_one" value="meal_one" /> Meal One</li> How many servings will you have? <input type="text" name="meal_one_servings"><br /><br /> <li><input type="checkbox" name="food_one" value="food_one" /> Food One</li> How many servings will you have? <input type="text" name="meal_one_servings"> </form> </ul> <input type="submit" value="delete" name="delete"><br /> <input type="submit" value="add to calendar" name="add_to_calendar"> <br /><br /> <a href="create-a-meal.php">Create A Meal & add to your Meal Que</a><br /> <a href="find-a-meal.php">Find a Meal or Food to Add to your Meal Que</a> </div> <div id="clear"></div> <?php include 'footer.php'; ?> </div> </div> Hey guys, i was recently making a new PHP code and when i tested it out it gave me this error: Code: [Select] mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\tools\edit_infos.php on line 167 I don't know what the problem is. Here is 'Line 167': Code: [Select] //Line 167 $dnn = mysql_fetch_array(mysql_query('select username,password,email,desc,keys,logo,webclient,forums,hiscores,chatbox,staff,newstitle,newsimage,news,op1,op2,op3 from users where username="'.$_SESSION['username'].'"')); $username = htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8'); $password = htmlentities($dnn['password'], ENT_QUOTES, 'UTF-8'); $email = htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8'); $desc = htmlentities($dnn['desc'], ENT_QUOTES, 'UTF-8'); $keys = htmlentities($dnn['keys'], ENT_QUOTES, 'UTF-8'); $logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8'); $webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8'); $forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8'); $hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8'); $chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8'); $staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8'); $newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8'); $newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8'); $news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8'); $op = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8'); $opp = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8'); $oppp = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8'); And here is the whole page code if needed. Code: [Select] <?php include('config.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" /> <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" /> <title>Edit my personnal informations</title> </head> <body> <div class="header"> <a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Members Area" /></a> </div> <?php //We check if the user is logged if(isset($_SESSION['username'])) { //We check if the form has been sent if(isset($_POST['username'], $_POST['password'], $_POST['passverif'], $_POST['email'], $_POST['desc'], $_POST['keys'], $_POST['logo'], $_POST['webclient'], $_POST['forums'], $_POST['hiscores'], $_POST['donate'], $_POST['chatbox'], $_POST['staff'], $_POST['newstitle'], $_POST['newsimage'], $_POST['news'], $_POST['op1'], $_POST['op2'], $_POST['op3'], $_POST['desc'])) { //We remove slashes depending on the configuration if(get_magic_quotes_gpc()) { $_POST['username'] = stripslashes($_POST['username']); $_POST['password'] = stripslashes($_POST['password']); $_POST['passverif'] = stripslashes($_POST['passverif']); $_POST['email'] = stripslashes($_POST['email']); $_POST['desc'] = stripslashes($_POST['desc']); $_POST['keys'] = stripslashes($_POST['keys']); $_POST['logo'] = stripslashes($_POST['logo']); $_POST['webclient'] = stripslashes($_POST['webclient']); $_POST['forums'] = stripslashes($_POST['forums']); $_POST['hiscores'] = stripslashes($_POST['hiscores']); $_POST['donate'] = stripslashes($_POST['logo']); $_POST['chatbox'] = stripslashes($_POST['chatbox']); $_POST['staff'] = stripslashes($_POST['staff']); $_POST['newstitle'] = stripslashes($_POST['newstitle']); $_POST['newsimage'] = stripslashes($_POST['newsimage']); $_POST['news'] = stripslashes($_POST['news']); $_POST['op1'] = stripslashes($_POST['op1']); $_POST['op2'] = stripslashes($_POST['op2']); $_POST['op3'] = stripslashes($_POST['op3']); } //We check if the two passwords are identical if($_POST['password']==$_POST['passverif']) { //We check if the password has 6 or more characters if(strlen($_POST['password'])>=6) { //We check if the email form is valid if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email'])) { //We protect the variables $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $email = mysql_real_escape_string($_POST['email']); $desc = mysql_real_escape_string($_POST['desc']); $keys = mysql_real_escape_string($_POST['keys']); $logo = mysql_real_escape_string($_POST['logo']); $webclient = mysql_real_escape_string($_POST['webclient']); $forums = mysql_real_escape_string($_POST['forums']); $hiscores = mysql_real_escape_string($_POST['hiscores']); $donate = mysql_real_escape_string($_POST['donate']); $chatbox = mysql_real_escape_string($_POST['chatbox']); $staff = mysql_real_escape_string($_POST['staff']); $newstitle = mysql_real_escape_string($_POST['newstitle']); $newsimage = mysql_real_escape_string($_POST['newsimage']); $news = mysql_real_escape_string($_POST['news']); $op = mysql_real_escape_string($_POST['op1']); $opp = mysql_real_escape_string($_POST['op2']); $oppp = mysql_real_escape_string($_POST['op3']); //We check if there is no other user using the same username $dn = mysql_fetch_array(mysql_query('select count(*) as nb from users where username="'.$username.'"')); //We check if the username changed and if it is available if($dn['nb']==0 or $_POST['username']==$_SESSION['username']) { //We edit the user informations if(mysql_query('update users set username="'.$username.'", password="'.$password.'", email="'.$email.'", desc="'.$desc.'", keys="'.$keys.'", logo="'.$logo.'", webclient="'.$webclient.'", forums="'.$forums.'", hiscores="'.$hiscores.'", chatbox="'.$chatbox.'", staff="'.$staff.'", newstitle="'.$newstitle.'", newsimage="'.$newsimage.'", news="'.$news.'", op1="'.$op1.'", op2="'.$op2.'", op3="'.$op3.'" where id="'.mysql_real_escape_string($_SESSION['userid']).'"')) { //We dont display the form $form = false; //We delete the old sessions so the user need to log again unset($_SESSION['username'], $_SESSION['userid']); ?> <div class="message">Your informations have successfuly been updated. You need to log again.<br /> <a href="connexion.php">Log in</a></div> <?php } else { //Otherwise, we say that an error occured $form = true; $message = 'An error occurred while updating your informations.'; } } else { //Otherwise, we say the username is not available $form = true; $message = 'The username you want to use is not available, please choose another one.'; } } else { //Otherwise, we say the email is not valid $form = true; $message = 'The email you entered is not valid.'; } } else { //Otherwise, we say the password is too short $form = true; $message = 'Your password must contain at least 6 characters.'; } } else { //Otherwise, we say the passwords are not identical $form = true; $message = 'The passwords you entered are not identical.'; } } else { $form = true; } if($form) { //We display a message if necessary if(isset($message)) { echo '<strong>'.$message.'</strong>'; } //If the form has already been sent, we display the same values if(isset($_POST['username'],$_POST['password'],$_POST['desc'], $_POST['keys'], $_POST['logo'], $_POST['webclient'], $_POST['forums'], $_POST['hiscores'], $_POST['donate'], $_POST['chatbox'], $_POST['staff'], $_POST['newstitle'], $_POST['newsimage'], $_POST['news'], $_POST['op1'], $_POST['op2'], $_POST['op3'])) { $pseudo = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8'); if($_POST['password']==$_POST['passverif']) { $password = htmlentities($_POST['password'], ENT_QUOTES, 'UTF-8'); } else { $password = ''; } $email = htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8'); $desc = htmlentities($_POST['desc'], ENT_QUOTES, 'UTF-8'); $keys = htmlentities($dnn['keys'], ENT_QUOTES, 'UTF-8'); $logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8'); $webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8'); $forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8'); $hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8'); $chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8'); $staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8'); $newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8'); $newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8'); $news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8'); $op = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8'); $opp = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8'); $oppp = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8'); } else { //otherwise, we display the values of the database $dnn = mysql_fetch_array(mysql_query('select username,password,email,desc,keys,logo,webclient,forums,hiscores,chatbox,staff,newstitle,newsimage,news,op1,op2,op3 from users where username="'.$_SESSION['username'].'"')); $username = htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8'); $password = htmlentities($dnn['password'], ENT_QUOTES, 'UTF-8'); $email = htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8'); $desc = htmlentities($dnn['desc'], ENT_QUOTES, 'UTF-8'); $keys = htmlentities($dnn['keys'], ENT_QUOTES, 'UTF-8'); $logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8'); $webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8'); $forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8'); $hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8'); $chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8'); $staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8'); $newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8'); $newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8'); $news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8'); $op = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8'); $opp = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8'); $oppp = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8'); } //We display the form ?> <div class="content"> <form action="edit_infos.php" method="post"> You can edit your informations:<br /> <div class="center"> <label for="username">Username</label><input type="text" name="username" id="username" value="<?php echo $username; ?>" /><br /> <label for="password">Password<span class="small">(6 characters min.)</span></label><input type="password" name="password" id="password" value="<?php echo $password; ?>" /><br /> <label for="passverif">Password<span class="small">(verification)</span></label><input type="password" name="passverif" id="passverif" value="<?php echo $password; ?>" /><br /> <label for="email">Email</label><input type="text" name="email" id="email" value="<?php echo $email; ?>" /><br /> <label for="desc">Webclient/Server Description</label><textarea name="desc" id="desc" rows="3" value="<?php echo $desc; ?>"></textarea><br /> <label for="keys">Webclient/Server Tags<span class="small">(Seperate with comma's)</span></label><input type="text" name="keys" id="keys" value="<?php echo $keys; ?>" /><br /> <label for="logo">Website/Server Logo Link</label><input type="text" name="logo" id="logo" value="<?php echo $logo; ?>" /><br /> <label for="webclient">Webclient Link</label><input type="text" name="webclient" id="webclient" value="<?php echo $webclient; ?>" /><br /> <label for="forums">Forums Link</label><input type="text" name="forums" id="forums" value="<?php echo $forums; ?>" /><br /> <label for="hiscores">Hiscores Link</label><input type="text" name="hiscores" id="hiscores" value="<?php echo $hiscores; ?>" /><br /> <label for="chatbox">Chatbox Html</label><textarea name="chatbox" rows="3" id="chatbox" value="<?php echo $chatbox; ?>" ></textarea><br /> <label for="staff">Staff Page Link</label><input type="text" name="staff" id="staff" value="<?php echo $staff; ?>" /><br /> <label for="newstitle">News Article Title</label><input type="text" name="newstitle" id="newstitle" value="<?php echo $newstitle; ?>" /><br /> <label for="newsimage">News Article Image Link<span class="small">(Displayed under title)</span></label><input type="text" name="newsimage" id="newsimage" value="<?php echo $newsimage; ?>" /><br /> <label for="news">News Article</label><textarea name="news" rows="3" id="news" value="<?php echo $news; ?>" ></textarea><br /> <label for="op1">Optional Link #1</label><input type="text" name="op" id="op" value="<?php echo $op; ?>" /><br /> <label for="op2">Optional Link #2</label><input type="text" name="opp" id="opp" value="<?php echo $opp; ?>" /><br /> <label for="op3">Optional Link #3</label><input type="text" name="oppp" id="oppp" value="<?php echo $oppp; ?>" /><br /> <input type="submit" value="Send" /> </div> </form> </div> <?php } } else { ?> <div class="message">To access this page, you must be logged.<br /> <a href="connexion.php">Log in</a></div> <?php } ?> <div class="foot"><a href="<?php echo $url_home; ?>">Go Home</a> - <a href="http://www.webestools.com/">Webestools</a></div> </body> </html>Anyway, i hope someone can help me solve this. Thanks 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> 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 . ""; } ?> This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319414.0 I keep getting a resource #6 at the top of my script and not sure why. <?php if (isset($_REQUEST['option'])) { switch ($_REQUEST['option']) { case 0: ?> <h1 class="backstage">Biographies Management</h1><br /> <h2 class=backstage>Bio Types</h2><br /> <?php $query = "SELECT * FROM efed_list_styles AS styles"; $result = mysql_query ( $query ); $rows = mysql_num_rows($result); if ($rows > 0) { print'<table width="100%" class="table1"> <tr class="rowheading"> <td> </td> <td width="40" align="center">ID</td> <td>Name</td> </tr>'; $i = 0; while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) { $sClass = 'row2'; if ($i++ % 2) $sClass = 'row1'; printf ( "<tr class=\"%s\">", $sClass ); print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"ajaxpage('backstage_libs/biolayout.php?option=1&id=$row[id].', 'content'); return false;\">Edit</a></td>"; printf ( "<td align=\"center\" valign=\"top\" width=\"40\">%s</td>", $row ['id'] ); printf ( "<td valign=\"top\">%s</td>", $row ['name'] ); echo '</tr>'; } echo '</table><br>'; } else { echo '<span>There are no bio types.</span><br /><br />'; } returnmain(); footercode(); break; case 1: require_once('../backstageconfig.php'); require_once('../backstagefunctions.php'); $id = $_GET['id']; $query = mysql_query("SELECT * FROM `efed_list_styles` WHERE `id` = '" . $id . "'"); $row = mysql_fetch_array($query); echo $query; ?> <h1 class="backstage">Bio Layouts Management</h1><br /> <h2 class="backstage"><?php echo $row['name']; ?> Biography Layout</h2><br /> <?php } } ?> Hey PHPFreaks. I made a php code, thats only needed to be showed for admin accounts only. I tryed to echo the mysql_num_rows($result); and it gave me this: Resource id #51 Heres a piece of my code where the problem is: $result = mysql_query("SELECT adminlevel FROM accounts WHERE name = '".$_SESSION['auth_username']."'") or die(mysql_error()); echo $result; echo mysql_num_rows($result); if(mysql_num_rows($result) == 1) { echo '<br /><br /><a href="home.php?admin">Admin Area</a>'; } Hope you can help Hello everyone, I am writing some code for a login script. I keep getting the error Resource ID #13. What does this mean and how can I fix it? Here is the code that I am having trouble with Code: [Select] function user_id_from_username($username) { $username = sanitize($username); $query = mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"); return mysql_result($query, 0, 'user_id'); } function login($username, $password) { $user_id = user_id_from_username($username); $username = sanitize($username); $password = md5($password); $query = "SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"; return (mysql_result(mysql_query($query), 0) == 1) ? $user_id : false; } I was expecting a return string, but got Resource id #2 instead. How do I have a string returned instead of that? heres my table user code Bob One Ted Two I dont get it Code: [Select] <html> <body> <?php $con = mysql_connect("localhost","user","PassWord"); if (!$con) { echo 'Could not connect to MySQL server. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error(); exit; } $db = mysql_select_db("userdb") or die("Unable to select database"); if (!$db) { echo 'Could not select db. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error(); exit; } $query = "SELECT code from usertbl WHERE user = 'Ted' LIMIT 0 , 30"; $result = mysql_query($query, $con); if (!$result) { echo 'Could not query server. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error(); exit; } echo $result; ?> </body> </html> When I use that query in phpmyadmin it works Any pointers much appreciated This works...
$result = mysql_query("SELECT * FROM login_attempts"); while($row = mysql_fetch_array($result)) { $diff = strtotime($row['login_date'])-time(); if ($diff > -300){ $count = $count + 1; } if ($count > 4) { $result = "locked"; } }This returns Resource ID 5... $result = mysql_query("SELECT * FROM login_attempts WHERE login_username='$username'"); while($row = mysql_fetch_array($result)) { $diff = strtotime($row['login_date'])-time(); if ($diff > -300){ $count = $count + 1; } if ($count > 4) { $result = "locked"; } }What's the problem? Many thanks, Hello everyone, I am writing some code for a login script. I keep getting the error Resource ID #13. What does this mean and how can I fix it? Here is the code that I am having trouble with Code: [Select] function user_id_from_username($username) { $username = sanitize($username); $query = mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"); return mysql_result($query, 0, 'user_id'); } function login($username, $password) { $user_id = user_id_from_username($username); $username = sanitize($username); $password = md5($password); $query = "SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"; return (mysql_result(mysql_query($query), 0) == 1) ? $user_id : false; } I'm trying to show my friend my website and it's not letting him or me view it. I am using my own IP-address. (dashed out for security, but it is correct) http://--.---.--.---/index-1.php When he and I type this into our browser, we can an error called "Resource Not Found". But, when I use localhost address, it works fine. http://localhost/index-1.php Does anyone know what is wrong? Do I need to open a specific port? USING XAMPP. Here is what is echoing the string "Resource id #1". However I do not know if it is the php or javascript that is outputting this. Can anyone tell me why this is showing and how to make it not show? PHP: Code: [Select] $directory = "Images/items/$product/"; //get all image files with a .jpg extension. $images = glob($directory . "*.jpg"); $imgone = $images[0]; $gallery = '<tr><td valign="top" align="center">'; foreach($images as $image) { $tn = explode("/", $image); $tnname = $tn[3]; $gallery .= '<a href="#" rel="'.$image.'" class="image" alt="Images/items/'.$product.'/large/'.$tnname.'"><img src="Images/items/'.$product.'/thumbs/'.$tnname.'" class="thumb" border="1" style="margin-bottom:7px;"/></a> '; } if(is_dir("Images/items/".$product)) $gallery .= "</td></tr><tr><td width='300'>".$link."<div id='image' class='bigimg' align='left'>"; if(is_dir('Images/items/'.$product)) $gallery .= '<img src="'.$imgone.'" border="0"/></div></a></td></tr>'; JS (jQuery) Code: [Select] $(function() { $(".image").click(function() { var image = $(this).attr("rel"); var large = $(this).attr("alt"); $('#image').hide(); $('#image').fadeIn('slow'); $('#image').html('<a href="' + large + '" ><img src="' + image + '"/></a>'); return false; }); }); How can I fix this error? Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given Code: [Select] function fetch_most_recent_fans($ctag) { $sql = "SELECT `company_fans`.`company_id`, `company_fans`.`user_id`, `company_fans`.`fan_date`, `companies`.`companytag`, `users`.`firstname`, `users`.`lastname`, `users`.`username` FROM `company_fans` LEFT JOIN `companies` ON `companies`.`companyid` = `company_fans`.`company_id` LEFT JOIN `users` ON `users`.`id` = `company_fans`.`user_id` WHERE `companies`.`companytag` = {ctag} ORDER BY `company_fans`.`fan_date` DESC LIMIT 10"; $query = mysql_query($sql); $return = array(); while (($row = mysql_fetch_assoc($query)) !== false) { $return[] = $row; } return $return; } Hi, I was in the process of making thumnails for avatars It used to work before but now the files are being saved as resource ID and not in an image format. I can not point out what the issue is and also may I add when I try to echo nothing is happening. Code: [Select] $filename = $_FILES['myfile']['tmp_name']; if ($_POST['cpic']) { // Set a maximum height and width $width = 100; $height = 100; // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; $ratio_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); $location = "cid/$myid/$filename"; imagejpeg($image_p, $location, 100); $query =mysql_query ("UPDATE clp SET avatar ='$location' WHERE cid='1'"); header ("LOCATION: editprofile.php"); } I keep getting the mysql resource id #4 on a query that I am running and I have tried everything that I have read to fix it and nothing is working. I tried using the mysql_fetch_array, mysql_fetch_accoc, and the mysql_fetch_row functions I would appreciate any help that can be given to me. Here is my code as it stands now Code: [Select] <?php include('includes/config.php'); $last = $_GET['l_name']; $first = $_GET['f_name']; $sql = 'SELECT * FROM `ttmautos` WHERE `l_name` LIKE \'$last\' AND `f_name` LIKE \'$first\''; $autographs = mysql_query($sql, $connection)or die(mysql_error()); $row = mysql_fetch_array($autographs); echo $sql; echo $autographs; $l_name = $row['l_name']; $f_name = $row['f_name']; $sent = $row['date_sent']; $return = $row['date_return']; $address = $row['address']; $isent = $row['item_sent']; $ireturn = $row['item_return']; $project = $row['project']; $team = $row['team']; $address = stripslashes($address); ?> If $result contains the result of mysql_query, a select count distinct query, how do I access the count? I've tried $result[0] to no avail and $result only returns the resource #. Okay, I have a table with two columns..'annoyed' and 'ignored'. I poulated 'annoyed' with Bob and 'ignored' with Sally. I ran the following test due to problems I was having in my main script and I get the old MySQL "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/testing_ig.php on line 16 Here is the code: <?php $DBhost = "localhost"; $DBuser = "xxxxx"; $DBpass = "xxxxx"; $DBName = "xxxxx"; $table = "ignore"; mysql_connect($DBhost,$DBuser,$DBpass) or die(); @mysql_select_db("$DBName") or die(); $ignorequery = "SELECT * FROM $table WHERE annoyed='Bob' AND ignored='Sally'"; $checkignore = mysql_query($ignorequery); $ifignored = mysql_num_rows($checkignore); //<--- This is line 16 if ($ifignored >= 1) { echo "exists"; } else { echo "doesn't exist"; } ?> I must be really tired because I'm not seeing the problem...? |