Jump to content

yoyo

New Members
  • Posts

    3
  • Joined

  • Last visited

yoyo's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. It didn't display the product, because in my database I do insert the data. the function.php code is : <? function get_product_name($pid){ $result=mysql_query("select name from products where serial=$pid"); $row=mysql_fetch_array($result); return $row['name']; } function get_price($pid){ $result=mysql_query("select price from products where serial=$pid"); $row=mysql_fetch_array($result); return $row['price']; } function remove_product($pid){ $pid=intval($pid); $max=count($_SESSION['cart']); for($i=0;$i<$max;$i++){ if($pid==$_SESSION['cart'][$i]['productid']){ unset($_SESSION['cart'][$i]); break; } } $_SESSION['cart']=array_values($_SESSION['cart']); } function get_order_total(){ $max=count($_SESSION['cart']); $sum=0; for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=$_SESSION['cart'][$i]['qty']; $price=get_price($pid); $sum+=$price*$q; } return $sum; } function addtocart($pid,$q){ if($pid<1 or $q<1) return; if(is_array($_SESSION['cart'])){ if(product_exists($pid)) return; $max=count($_SESSION['cart']); $_SESSION['cart'][$max]['productid']=$pid; $_SESSION['cart'][$max]['qty']=$q; } else{ $_SESSION['cart']=array(); $_SESSION['cart'][0]['productid']=$pid; $_SESSION['cart'][0]['qty']=$q; } } function product_exists($pid){ $pid=intval($pid); $max=count($_SESSION['cart']); $flag=0; for($i=0;$i<$max;$i++){ if($pid==$_SESSION['cart'][$i]['productid']){ $flag=1; break; } } return $flag; } ?>
  2. I had amended to this : <?php include("includes/db.php"); include("includes/functions.php"); error_reporting (E_ALL ^ E_NOTICE); if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){ $pid=$_REQUEST['productid']; addtocart($pid,1); header("location:shoppingcart.php"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Products</title> <script language="javascript"> function addtocart(pid){ document.form1.productid.value=pid; document.form1.command.value='add'; document.form1.submit(); } </script> </head> <body> <form name="form1"> <input type="hidden" name="productid" /> <input type="hidden" name="command" /> </form> <div align="center"> <h1 align="center">Products</h1> <table border="0" cellpadding="2px" width="600px"> <? $result=mysql_query("select * from products"); while($row=mysql_fetch_array($result)){ ?> <tr> <td><img src="<?=$row['picture']?>" /></td> <td> <b><?=$row['name']?></b><br /> <?=$row['description']?><br /> Price:<big style="color:green"> $<?=$row['price']?></big><br /><br /> <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['serial']?>)" /> </td> </tr> <tr><td colspan="2"><hr size="1" /></td> <? } ?> </table> </div> </body> </html> It didn't have error but it still can't display the database in phpMyAdmin... What should I do?
  3. Hi, I am newbie for PHP and MySQL I found this error, please help me. Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Shopping\products.php on line 39 Here the full coding: <?php include("includes/db.php"); include("includes/functions.php"); error_reporting (E_ALL ^ E_NOTICE); if($_REQUEST['command']=='add' && $_REQUEST['productid']>0) { $pid=$_REQUEST['productid']; addtocart($pid,1); header("location:shoppingcart.php"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Products</title> <script language="javascript"> function addtocart(pid){ document.form1.productid.value=pid; document.form1.command.value='add'; document.form1.submit(); } </script> </head> <body> <form name="form1"> <input type="hidden" name="productid" /> <input type="hidden" name="command" /> </form> <div align="center"> <h1 align="center">Products</h1> <table border="0" cellpadding="2px" width="600px"> <?php $result=mysql_query("select * from products"); while($row=mysql_fetch_array($result)){extract($row); ?> <tr> <td><img src="<?php echo $row['picture']?>" /></td> <td> <b><?php echo $row['name']?></b><br /> <?php echo $row['description']?><br /> Price:<big style="color:green"> RM<?php echo $row['price']?></big><br /><br /> <input type="button" value="Add to Cart" onclick="addtocart(<?php echo $row['serial']?>)" /> </td> </tr> <tr><td colspan="2"><hr size="1" /></td> <?php } ?> </table> </div> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.