Issues with mysql_fetch_assoc()
Posted: Tue Aug 31, 2010 5:48 pm
Hey, I keep getting an error when i try and load this page. It keeps saying "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in **********************"
This is the code:
This is the code:
Code: Select all
<?php
mysql_connect("*****", "*****", "*****") or die(mysql_error());
mysql_select_db("a*****") or die(mysql_error());
$result = mysql_query("SELECT * FROM test");
function lookup($wanted) //Part number of the item this form is for.
{
do { // Does the searching for the part name and the price.
$row = mysql_fetch_assoc($result);
$id = $row['id']; // Part number in the database
$price = $row['price']; //Price listed for part number in the database
} while ($id != $wanted);
}
?>
<html>
<head>
</head>
<body>
<script type="text/javascript">
function UpdateCost() {
var sum = 0;
var qty,
prc;
for (i=1; i<49; i++) {
qty = 'qty'+i;
prc = 'price'+i;
if
(document.getElementById(qty).checked == true)
{
sum += Number(document.getElementById(prc).value);
}
}
document.getElementById('totalcost').value = sum.toFixed(2);
}
</script>
# 236261 Engine A55 cpl. - kick * Inquire<br>
# 236274 Engine A55 cpl. - pedal * Inquire<br>
<form action="*****" method="post">
<input name="userid" type="hidden" value="*****">
<input type="hidden" name="return" value="*****">
<? lookup("230950"); ?>
<input type="hidden" name="product1" value="1/1 Crankcase A55 cpl. - kick <? echo $price; ?> ">
<input type="checkbox" id="qty1" name="qty1" value="1" onClick="UpdateCost()">
<input type="hidden" id="price1" name="price1" value="<? echo $price; ?>">1/1 # 230940 Crankcase A55 cpl. - kick <? echo $price; ?>
<br>
.....
.....