Reputation: 86
I'm trying to get information about cost
in database items
by name
and img getting error Resource id #5
My set.php
<?php
$sitename = "localhost";
$link = mysql_connect("localhost", "root", "");
$db_selected = mysql_select_db('csgo', $link);
mysql_query("SET NAMES utf8");
function fetchinfo($rowname,$tablename,$finder,$findervalue) {
if($finder == "1") $result = mysql_query("SELECT $rowname FROM $tablename");
else $result = mysql_query("SELECT $rowname FROM $tablename WHERE `$finder`='$findervalue'");
$row = mysql_fetch_assoc($result);
return $row[$rowname];
}
?>
And my code to get cost
<?php
$item = $_GET['item'];
$item = str_replace("\"", "", $item);
$item = str_replace("\'", "", $item);
$item = str_replace(" ", "%20", $item);
$item = str_replace("\\", "", $item);
@include_once ("set.php");
$item_cost = mysql_query("SELECT cost FROM items WHERE name='$item'");
echo $item_cost;
?>
Upvotes: 0
Views: 45
Reputation: 463
You are trying to echo the result resource of the executed sql query.
You have pass this resource e.g. to mysql_fetch_array() and then can loop over that array (see http://php.net/manual/de/function.mysql-query.php)
Upvotes: 1
Reputation: 713
First of all, stop using mysql_*
and start using mysqli_*
, check the warning at http://php.net/manual/en/function.mysql-query.php
Check this tutorial http://codular.com/php-mysqli
Resource id #5
is not an error, the mysql_query
function doesn't directly return the output of the SQL Query, it returns an object that you should loop on, for example
<?php
$sql = 'SELECT * FROM `users` WHERE `live` = 1';
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = $result->fetch_assoc()){
echo $row['username'] . '<br />';
}
Upvotes: 1