PHP - Hide Resource Id #1
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; }); }); Similar TutorialsHello 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; } 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, 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 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 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 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 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); ?> 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"); } Hi, 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(); } ?> 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 #. 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. 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; } I always use my queries like below mysql_query("SELECT id FROM someTable", $cn); but some times i see in my error_log says: mysql_fetch_array(): supplied argument is not a valid MySQL result resource. Why is this happening? I mean, there is no problem with my sites and all they are working as they should be but why php generates this error? 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...? 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; }
Hi I've just started to learn PHP and I'm having a little trouble. I'm trying to stick with OOP but I'm having trouble with it. I've coded a database connection and I'm trying to take data from a form and insert it into a database. I've managed to do it without OOP but I can't get it to work with. The code is below. Any help would be great. I have a file for the form, which should take the data and the php should insert it into the table - <?php // Get the PHP file containing the dbConnect class require('../../configuration.php'); // Get the PHP file containing the dbConnect class require('../../lib/db.class.php'); // Checks whether a form has been submitted. If so, carry on if ($_POST) { // Creates an instance of dbConnect $link = new dbConnect(); // Creates a SQL query $insertQuery = 'INSERT INTO content SET title = "' . $_POST['title'] . '", alias = "' . $_POST['alias'] . '", category = "' . $_POST['category'] . '", summary = "' . $_POST['summary'] . '", content = "' . $_POST['content'] . '"'; $result = $link->query($insertQuery, $link); } ?> <body> <form action="" method="post"> <div> <label for="title">Title:</label> <textarea id="title" name="title" rows="1" cols="30"> </textarea> </div> <div> <label for="alias">Alias:</label> <textarea id="alias" name="alias" rows="1" cols="30"> </textarea> <div> <label for="category">Category:</label> <textarea id="category" name="category" rows="1" cols="30"> </textarea> </div> <div> <label for="summary">Summary:</label> <textarea id="summary" name="summary" rows="6" cols="40"> </textarea> </div> <div> <label for="content">Content:</label> <textarea id="content" name="content" rows="12" cols="40"> </textarea> </div> <div> <input type="submit" value="Add Article" /> </div> </form> This is my class to connect to the db - class dbConnect extends siteConfig { var $theQuery; var $link; // Function to connect to the database public function dbConnect() { // Load configuration from parent class $config = siteConfig::getConfig(); // Get main config settings from the array that we just loaded $host = $config['hostname']; $user = $config['username']; $pass = $config['password']; $db = $config['database']; // Connect to the DB $link = mysql_connect('localhost', 'user', 'pass'); if (!$link) { $error = 'Unable to connect to the database server.'; echo $error; exit(); } } // Function to execute a database query public function query($link, $query) { $this->theQuery = $query; mysql_query($this->link, $query); } // Function to get array of query results public function getArray($result) { return mysql_fetch_array($result); } // Function to close the connection public function closeConnection() { mysql_close($this->link); } } I also have a config file. I'm not using it atm but I thought I'd show it anyway as it may help - class siteConfig { var $config; function getConfig() { $config['site_url'] = 'localhost/edencms'; $config['hostname'] = 'localhost'; $config['username'] = 'user'; $config['password'] = 'pass'; $config['database'] = 'edencms'; } } After filling out the form and sending it, I get the following error: Quote Warning: mysql_query() expects parameter 2 to be resource, object given in C:\xampp\htdocs\EdenCMS\lib\db.class.php on line 39 It seems like $link isn't staying as a resource once the dbConnect is called. If I print it in the dbConnect function, it shows it's a resource but if I try to print it after, it shows as an object. I'm not sure why. As I said, I'm new, so go easy I need to post form data from a page (about 6 fields) to a XML form resource which will responce with a secuss or failure message. After looking around I fount this script that will allow me to post XML data using cURL. my question is can someone point me in the right direction for firing this post off after the user enters data into the fields and hits the submit button. Also what would be the cleanest way to get the form data into the XML section of the below code. What is the best way to handle this? Thanks! <?php $url = "http://www.some_domain.com"; $post_string = '<?xml version="1.0" encoding="UTF-8"?> <rootNode> <innerNode> </innerNode> </rootNode>'; $header = "POST HTTP/1.0 \r\n"; $header .= "Content-type: text/xml \r\n"; $header .= "Content-length: ".strlen($post_string)." \r\n"; $header .= "Content-transfer-encoding: text \r\n"; $header .= "Connection: close \r\n\r\n"; $header .= $post_string; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); $data = curl_exec($ch); if(curl_errno($ch)) print curl_error($ch); else curl_close($ch); ?> Hi I'm having a bit of bother with my login. I created a login using this tutorial http://www.phpeasystep.com/phptu/6.html and it works perfectly. So i have attempted to change it to meet my own database. So basically i've changed the database, table names etc to meet my own. I haven't changed any other lines. When i run it i get an error message: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\checklogin.php on line 26 The code is below: Code: [Select] <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="final year project"; // Database name $tbl_name="tbl_user"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $mem_username=$_POST['mem_username']; $mem_password=$_POST['mem_password']; // To protect MySQL injection (more detail about MySQL injection) $mem_username = stripslashes($mem_username); $mem_password = stripslashes($mem_password); $mem_username = mysql_real_escape_string($mem_username); $mem_password = mysql_real_escape_string($mem_password); $sql="SELECT * FROM $tbl_name WHERE username='$mem_username' and password='$mem_password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $mem_username and $mem_password, table row must be 1 row if($count==1){ // Register $mem_username, $mem_password and redirect to file "login_success.php" session_register("mem_username"); session_register("mem_password"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> Line 26 is $count=mysql_num_rows($result); I'm baffled as to why the test database worked. I tried another test database but got the same error. baffled.com Hope someone can help MOD EDIT: [code] . . . [/code] tags added. |