Hello,

I'm pretty new to php and i am trying to get the code below to work but i get the following error:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.5.0\www\Aution\itemdetails.php on line 14

The code is:

<?php
session_start();
include('config.php');
include('functions.php');
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
$validid = pf_validate_number($_GET["id"], "redirect", $config_basedir);
require('head.php');
$itemsql = 'SELECT UNIX_TIMESTAMP(dateends) AS dateepoch,
items.* FROM items WHERE id = ' . $validid . ';';

echo '<div id= "Table">';
$itemresult = mysql_query($itemsql);
$itemrow = mysql_fetch_assoc($itemresult);

$validid = pf_validate_number($_GET["id"], 'redirect',
$config_basedir);

$nowepoch = time();
$rowepoch = $itemrow['dateepoch'];
if($rowepoch > $nowepoch) {
$VALIDAUCTION = 1;
}
echo '<h2>' . $itemrow['name'] . '</h2>';
$imagesql = 'SELECT * FROM images WHERE item_id = ' . $validid . ';';
$imageresult = mysql_query($imagesql);
$imagenumrows = mysql_num_rows($imageresult);
$bidsql = "SELECT item_id, MAX(amount) AS highestbid,
COUNT(id) AS number_of_bids FROM bids WHERE item_id="
. $validid . "GROUP BY item_id;";
$bidresult = mysql_query($bidsql);
$bidnumrows = mysql_num_rows($bidresult);
echo '<p>';
if($bidnumrows == 0) {
echo '<strong>This item has had no bids</strong>
- <strong>Starting Price</strong>: ' . $config_currency
. sprintf('%.2f', $itemrow['startingprice']);
}
else {
$bidrow = mysql_fetch_assoc($bidresult);
echo '<strong>Number Of Bids</strong>: '
. $bidrow['number_of_bids'] . '
- <strong>Current Price</strong>: ' . $config_currency
. sprintf('%.2f', $bidrow['highestbid']);
}
echo ' - <strong>Auction ends</strong>: '
. date('D jS F Y g.iA', $rowepoch);
echo '</p>';
if($imagenumrows == 0) {
echo 'No images.';
}
else {
while($imagerow = mysql_fetch_assoc($imageresult)) {
//echo '<img src=’./images/' . $imagerow['name'] . ' width='200'>';
}
}


echo '<p>' . nl2br($itemrow['description']) . '</p>';
echo '<a name=bidbox>';
echo '<h2>Bid for this item</h2>';
if(isset($_SESSION['USERNAME']) == FALSE) {
echo 'To bid, you need to log in. Login
<a href=’login.php?id=' . $validid . '&ref=addbid’>here</a>.';
}
else {
if($VALIDAUCTION == 1) {
echo 'Enter the bid amount into the box below.';
echo '<p>';
switch($_GET['error']) {
case 'lowprice':
echo 'The bid entered is too low.
Please enter another price.';
break;
case 'letter':
echo 'The value entered is not a number.';
break;
}
}
}
echo '</div>';
?>

Thanks

Member Avatar for TechySafi
$itemsql = 'SELECT UNIX_TIMESTAMP(dateends) AS dateepoch,
items.* FROM items WHERE id = ' . $validid . ';';

Try this

$itemsql = 'SELECT UNIX_TIMESTAMP(dateends) AS dateepoch * FROM items WHERE id = '.$validid;

Not pretty sure if it gonna work or not :P Btw let me know what happens.

Try to debug your code.
Add below code at line#11

echo $itemsql; exit;

Use that query and run in phpmyadmin.
Check output result.

You do not test for failure of your functions. Try changing to these

<?php
session_start();
include('config.php');
include('functions.php');
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
if (!$db) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($dbdatabase, $db);
if (!$db_selected) {
    die ('Can\'t use database : ' . mysql_error());
}
$validid = pf_validate_number($_GET["id"], "redirect", $config_basedir);
require('head.php');

Run your code with these. Are you still good?
It would be nice to see these files.
include('config.php');
include('functions.php');
require('head.php');

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.