Dear friend,
When i try some sections of my code i receive this error message :
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
this is my code:
<?php
function proheader(){
echo "<html>"
."<head>"
."<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">"
."<title>Parto Cable Products List</title>"
."</head>"
."<body bgcolor=\"#7C3203\" topmargin=\"0\" leftmargin=\"0\">"
."<div align=\"center\">"
."<center>"
."<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"770\" height=\"471\">"
."<tr>"
."<td height=\"154\">"
."<img border=\"0\" src=\"parto-head.jpg\" width=\"770\" height=\"154\"></td>"
."</tr>"
."<tr>"
."<td valign=\"top\">";
}
function profooter(){
echo "</td></tr></table></center></div></body></html>";
}
function prolist(){
proheader();
$id = @$_POST['q'];
echo "<center><b>Prodults List</b></center>";
echo "<table border=\"1\" celpadding=\"1\" celspacing=\"1\" width=\"100%\">"
."<tr>"
."<td align=\"center\" bgcolor=\"#8a4323\"><b>Product ID</b>"
."</td>"
."<td align=\"center\" bgcolor=\"#8a4323\"><b>Product Group</b>"
."</td>"
."<td align=\"center\" bgcolor=\"#8a4323\"><b>Product Name</b>"
."</td>"
."<td align=\"center\" bgcolor=\"#8a4323\"><b>Detail</b>"
."</td>"
."</tr>";
mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("xxx") or die("Unable to select database");
$query = "select * from products where package = $id";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
for ($i=0; $i <$numrows; $i++)
{
$row = mysql_fetch_array($numresults);
$pid = intval($row['pid']);
$name = $row['name'];
$package = $row['package'];
echo "<tr>"
."<td align=\"center\">$pid"
."</td>"
."<td align=\"center\">$package"
."</td>"
."<td align=\"center\">$name"
."</td>"
."<td align=\"center\"><a href=\"prolist.php?iop=details&pid=$pid\">Details</a>"
."</td>"
."</tr>";
}
echo "</table>";
profooter();
}
function details($pid){
proheader();
$pid = intval($pid);
$query = "select * from products where pid = $pid";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
$row = mysql_fetch_array($numresults);
$name = $row['name'];
$cna = $row['cna'];
$nds = $row['nds'];
$hop = $row['hop'];
$it = $row['it'];
$ft = $row['ft'];
$st = $row['st'];
$mod = $row['mod'];
$mcr = $row['mcr'];
$mir = $row['mir'];
$cc = $row['cc'];
$wa = $row['wa'];
$cwa = $row['cwa'];
$bl = $row['bl'];
$package = $row['package'];
echo "<div align=\"center\">";
echo "<center><b>Prodults List $pid</b></center>";
echo "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" width=\"100%\">"
."<tr>"
."<td width=\"50%\">Product ID</td>"
."<td width=\"50%\"> $pid</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">Product Group</td>"
."<td width=\"50%\"> $package</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">Product Name</td>"
."<td width=\"50%\"> $name</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">CNA</td>"
."<td width=\"50%\"> $cna</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">NDS</td>"
."<td width=\"50%\"> $nds</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">HOP</td>"
."<td width=\"50%\"> $hop</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">IT</td>"
."<td width=\"50%\"> $it</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">FT</td>"
."<td width=\"50%\"> $ft</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">ST</td>"
."<td width=\"50%\"> $st</td>"
."</tr>"
."<td width=\"50%\">MOD</td>"
."<td width=\"50%\"> $mod</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">MCR</td>"
."<td width=\"50%\"> $mcr</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">MIR</td>"
."<td width=\"50%\"> $mir</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">CC</td>"
."<td width=\"50%\"> $cc</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">WA</td>"
."<td width=\"50%\"> $wa</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">CWA</td>"
."<td width=\"50%\"> $cwa</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">BL</td>"
."<td width=\"50%\"> $bl</td>"
."</tr>"
."<tr>"
."<td width=\"50%\">Order</td>"
."<td width=\"50%\"><a href=\"prolist.php?iop=order&pid=$pid\">Order Now!</a></td>"
."</tr>"
."</table></div>";
profooter();
}
function order($pid){
proheader();
$pid = intval($pid);
$query = "select * from products where pid = 2";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
$row = mysql_fetch_array($numresults);
$name = $row['name'];
echo "<div align=\"center\">"
."<center><b>Note: All fields are required!</b></center><br>"
."<form method=\"POST\" action=\"prolist.php\" name=\"form\">"
."<table border=\"1\" width=\"26%\">"
."<tr>"
."<td><b>Name</b></td>"
."<td width=\"148\"><input type=\"text\" name=\"customername\" size=\"20\"></td>"
."</tr>"
."<tr>"
."<td><b>Lname</b></td>"
."<td width=\"148\"><input type=\"password\" name=\"customerlname\" size=\"20\"></td>"
."</tr>"
."<tr>"
."<td><b>City</b></td>"
."<td width=\"148\"><input type=\"text\" name=\"customercity\" size=\"20\"></td>"
."</tr>"
."<tr>"
."<td><b>Tel</b></td>"
."<td width=\"148\"><input type=\"text\" name=\"customertel\" size=\"20\"></td>"
."</tr>"
."<tr>"
."<td><b>Fax</b></td>"
."<td width=\"148\"><input type=\"text\" name=\"customerfax\" size=\"20\"></td>"
."</tr>"
."<tr>"
."<td><b>Email</b></td>"
."<td width=\"148\"><input type=\"text\" name=\"customeremail\" size=\"20\"></td>"
."</tr>"
."<tr>"
."<td><b>Website</b></td>"
."<td width=\"148\"><input type=\"text\" name=\"customerwebsite\" size=\"20\"></td>"
."</tr>"
."<tr>"
."<td><b>Product</b></td>"
."<td width=\"148\"><input type=\"text\" name=\"product\" size=\"20\" value=\"$name\"></td>"
."</tr>"
."<tr>"
."<td><b>Amount</b></td>"
."<td width=\"148\"><input type=\"text\" name=\"ordervalue\" size=\"20\"></td>"
."</tr>"
."</table>"
."<input type=\"hidden\" name=\"iop\" value=\"ordersubmit\">"
."<p><input type=\"submit\" value=\"Submit\" style=\"border: 3px double #FFFFFF\"> <input type=\"reset\" value=\"Reset\" style=\"border: 3px double #FFFFFF\"></p>"
."</form></div>";
profooter();
}
function ordersubmit(){
proheader();
$customername = @$_POST['customername'];
$customerlname = @$_POST['customerlname'];
$customercity = @$_POST['customercity'];
$customertel = @$_POST['customertel'];
$customerfax = @$_POST['customerfax'];
$customeremail = @$_POST['customeremail'];
$customerwebsite = @$_POST['customerwebsite'];
$product = @$_POST['product'];
$ordervalue = @$_POST['ordervalue'];
if ($customername == ""){
echo"<center>You must enter your name !</center><br>"
."<center><a href=\"javascript:history.back()\">Go Back</a></center><br>";
exit;
}
elseif ($customerlname == ""){
echo"<center>You must enter your last name!</center><br>"
."<center><a href=\"javascript:history.back()\">Go Back</a></center><br>";
exit;
}
elseif ($customercity == ""){
echo"<center>You must enter your city!</center><br>"
."<center><a href=\"javascript:history.back()\">Go Back</a></center><br>";
exit;
}
elseif ($customertel == ""){
echo"<center>You must enter your telphone number!</center><br>"
."<center><a href=\"javascript:history.back()\">Go Back</a></center><br>";
exit;
}
elseif ($customeremail == ""){
echo"<center>You must enter your email!</center><br>"
."<center><a href=\"javascript:history.back()\">Go Back</a></center><br>";
exit;
}
elseif ($product == ""){
echo"<center>You must enter the product name!</center><br>"
."<center><a href=\"javascript:history.back()\">Go Back</a></center><br>";
exit;
}
elseif ($ordervalue == ""){
echo"<center>You must enter your order value!</center><br>"
."<center><a href=\"javascript:history.back()\">Go Back</a></center><br>";
exit;
}
else {
$add_all = "INSERT INTO orders values('','$customername','$customerlname','$customercity','$customertel','$customerfax', '$customeremail', '$customerwebsite', '$product', '$ordervalue')";
mysql_query($add_all) or die(mysql_error());
}
profooter();
}
function thankyou(){
proheader();
echo"<center>Thank You !Your order was received succesfully!</center>";
profooter();
}
$iop = $_GET['iop'];
switch($iop){
default:
prolist();
break;
case "details":
details($pid);
break;
case "order":
order($pid);
break;
case "ordersubmit":
ordersubmit();
break;
case "thankyou":
thankyou();
break;
}
?>
You can try my prolist.php file at following address :
http://www.partocable.com
Please help me with this issue.
Regards
Mansour