Forums

PHP

This topic is locked

Errors on webpage

Posted 21 Apr 2009 00:31:20
1
has voted
21 Apr 2009 00:31:20 hassan ruby posted:
Hi

Im geting the following errors displayed on my webpage.

Notice: Undefined index: SESS_USERID in C:\wamp\www\website\functions.php on line 31

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\website\functions.php on line 34

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\website\functions.php on line 39

Here is the code for functions.php



<?php
function pf_validate_number($value, $function, $redirect) {
if(isset($value) == TRUE) {
if(is_numeric($value) == FALSE) {
$error = 1;
}
if($error == 1) {
header("Location: " . $redirect);
}
else {
$final = $value;
}
}
else {
if($function == 'redirect') {
header("Location: " . $redirect);
}
if($function == "value") {
$final = 0;
}
}
return $final;
}
function showcart()
{
if($_SESSION['SESS_ORDERNUM'])
{
echo
$custsql = "SELECT id, status from
orders WHERE customer_id = "
. $_SESSION['SESS_USERID']
. " AND status < 2;";
$custres = mysql_query($custsql);
$custrow = mysql_fetch_assoc($custres);
$itemssql = "SELECT products.*, orderitems.*, orderitems.id AS
itemid FROM products, orderitems WHERE orderitems.product_id =
products.id AND order_id = " . $custrow['id'];
$itemsres = mysql_query($itemssql);
$itemnumrows = mysql_num_rows($itemsres);
}
else
{
$custsql = "SELECT id, status from orders WHERE session = '" . session_id() . "' AND status < 2;";
$custres = mysql_query($custsql);
$custrow = mysql_fetch_assoc($custres);
$itemssql = "SELECT products.*,
orderitems.*, orderitems.id AS itemid
FROM products, orderitems WHERE
orderitems.product_id = products.id AND
order_id = " . $custrow['id'];
$itemsres = mysql_query($itemssql);
$itemnumrows = mysql_num_rows($itemsres);
// If no SESS_ORDERNUM variable is available, the $itemnumrows variable is set to 0:
$itemnumrows = mysql_num_rows($itemsres);
}
}
if(isset($itemnumrows) && $itemnumrows == 0)
{
echo "You have not added anything to your shopping cart yet.";
}
else
{
echo "<table cellpadding='10'>";
echo "<tr>";
echo "<td></td>";
echo "<td><strong>Item</strong></td>";
echo "<td><strong>Quantity</strong></td>";
echo "<td><strong>Unit Price</strong></td>";
echo "<td><strong>Total Price</strong></td>";
echo "<td></td>";
echo "</tr>";
while($itemsrow = mysql_fetch_assoc($itemsres))
{
$quantitytotal =
$itemsrow['price'] * $itemsrow['quantity'];
echo "<tr>";
if(empty($itemsrow['image'])) {
echo "<td><img
src='./productimages/dummy.jpg' width='50' alt='"
. $itemsrow['name'] . "'></td>";
}
else {
echo "<td><img src='./productimages/" .
$itemsrow['image'] . "' width='50' alt='"
. $itemsrow['name'] . "'></td>";
}
echo "<td>" . $itemsrow['name'] . "</td>";
echo "<td>" . $itemsrow['quantity'] . "</td>";
echo "<td><strong>£"
. sprintf('%.2f', $itemsrow['price'])
. "</strong></td>";
echo "<td><strong>£"
. sprintf('%.2f', $quantitytotal) . "</strong></td>";
echo "<td>[<a href='"
. $config_basedir . "delete.php?id="
. $itemsrow['itemid'] . "'>X</a>]</td>";
echo "</tr>";
$total = $total + $quantitytotal;
$totalsql = "UPDATE orders SET total = "
. $total . " WHERE id = "
. $_SESSION['SESS_ORDERNUM'];
$totalres = mysql_query($totalsql);
}
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td>TOTAL</td>";
echo "<td><strong>£"
. sprintf('%.2f', $total) . "</strong></td>";
echo "<td></td>";
echo "</tr>";
echo "</table>";
echo "<p><a href='checkout-address.php'>Go to the checkout</a></p>";
}
?>






Replies

Replied 18 May 2009 18:10:16
18 May 2009 18:10:16 Roddy Dairion replied:
Its exactly what the error is telling you. SESS_USERID has not been define anywhere.
Now this is a real error its more like a warning.
Where is SESS_USERID defined???
Are you using session_start(); at the begining of the page where you're calling this function??

Reply to this topic