
UnknownZ
Members-
Posts
12 -
Joined
-
Last visited
UnknownZ's Achievements

Newbie (1/5)
0
Reputation
-
sorry for late reply.. the power was out yesterday. where to start exactly?
-
Cart string(51) "SELECT * FROM products WHERE id IN) ORDER BY id ASC" this is the error now $sql = substr($sql,0,-1). ") ORDER BY id ASC"; var_dump($sql);die(); <<<after putting this $query = mysql_query($sql) or die(mysql_error());
-
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY id ASC' at line 1 now this one shows up after putting it. here is my code <?php session_start(); require_once("storescripts/connect_to_mysql.php"); if(isset($_GET['page'])){ $pages = array("prod","cart"); if(in_array($_GET['page'],$pages)){ $page = $_GET['page']; } else { $page = "prod"; } }else { $page = "prod"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url=http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]"[]> <html xmlns="[url=http://www.w3.org/1999/xhtml]http://www.w3.org/1999/xhtml[/url]" dir="ltr" lang="en-US" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Home</title> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="script.js"></script> </head> <body> <div id="art-main"> <div class="cleared reset-box"></div> <div class="art-box art-sheet"> <div class="art-box-body art-sheet-body"> <div class="art-header"> <div class="art-logo"> </div> </div> <div class="cleared reset-box"></div> <div class="art-bar art-nav"> <div class="art-nav-outer"> <ul class="art-hmenu"> <li> <a href="index.php" class="active">Home</a> </li> <li> <a href="product.php">Product</a> </li> <li> <a href="about.html">About</a> </li> </ul> </div> </div> <div class="cleared reset-box"></div> <div class="art-layout-wrapper"> <div class="art-content-layout"> <div class="art-content-layout-row"> <div class="art-layout-cell art-sidebar1"> <div class="art-box art-vmenublock"> <div class="art-box-body art-vmenublock-body"> <div class="art-bar art-vmenublockheader"> <h3 class="t">Cart</h3> </div> <div class="art-box art-vmenublockcontent"> <div class="art-box-body art-vmenublockcontent-body"> <?php if(isset($_SESSION['cart'])){ $sql = "SELECT * FROM products WHERE id IN("; foreach($_SESSION['cart'] as $id => $value){ $sql .= $id. ","; } $sql = substr($sql,0,-1). ") ORDER BY id ASC"; $query = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($query)){ ?> <p><?php echo $row['product_name']; ?><?php echo" " .$_SESSION['cart'][$row['id']]['quantity'];?></p> <?php } }else { echo "<p>Your cart is empty. <br />Please add some products</p>"; } echo "<a href='product.php?page=cart'>Go to Cart</a>"; ?> <div class="cleared"></div> </div> </div> <div class="cleared"></div> </div> </div> <div class="art-box art-block"> <div class="art-box-body art-block-body"> <div class="art-bar art-blockheader"> <h3 class="t">Login</h3> </div> <div class="art-box art-blockcontent"> <div class="art-box-body art-blockcontent-body"> <div> </div> <div class="cleared"></div> </div> </div> <div class="cleared"></div> </div> </div> <div class="cleared"></div> </div> <div class="art-layout-cell art-content"> <div class="art-box art-post"> <div class="art-box-body art-post-body"><?php require($page . ".php");?> <div class="cleared"></div> </div> </div> <div class="art-box art-post"> <div class="cleared"></div> <div class="cleared"></div> </div> </div> <div class="cleared"></div> </div> </div> </div> </div> <div class="cleared"></div> <div class="art-footer"> <div class="art-footer-body"> <div class="art-footer-text">anonymous</div> <div class="cleared"></div> </div> </div> <div class="cleared"></div> </div> </div> <div class="cleared"></div> </div> </body> </html>
-
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\cart\product.php on line 72 <?php if(isset($_SESSION['cart'])){ $sql = "SELECT * FROM products WHERE id IN("; foreach($_SESSION['cart'] as $id => $value){ $sql .= $id. ","; } $sql = substr($sql,0,-1). ") ORDER BY id ASC"; $query = mysql_query($sql); while ($row = mysql_fetch_array($query)){ [size=6] <<<<< Line 72 HERE[/size] ?> <p><?php echo $row['product_name']; ?><?php echo" " .$_SESSION['cart'][$row['id']]['quantity'];?></p> <?php } }else { echo "<p>Your cart is empty. <br />Please add some products</p>"; } echo "<a href='product.php?page=cart'>Go to Cart</a>"; ?>
-
so i can put it all in one page. but i dont know how
-
so how can i fix it then? what should i use?
-
<?php // This file is www.developphp.com curriculum material // Written by Adam Khoury January 01, 2011 // http://www.youtube.com/view_play_list?p=442E340A42191003 session_start(); // Start session first thing in script // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 1 (if user attempts to add something to the cart from the product page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_POST['pid'])) { $pid = $_POST['pid']; $wasFound = false; $i = 0; // If the cart session variable is not set or cart array is empty if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { // RUN IF THE CART IS EMPTY OR NOT SET $_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1)); } else { // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT foreach ($_SESSION["cart_array"] as $each_item) { $i++; while (list($key, $value) = each($each_item)) { if ($key == "item_id" && $value == $pid) { // That item is in cart already so let's adjust its quantity using array_splice() array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1))); $wasFound = true; } // close if condition } // close while loop } // close foreach loop if ($wasFound == false) { array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1)); } } header("location: cart.php"); exit(); } ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 2 (if user chooses to empty their shopping cart) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") { unset($_SESSION["cart_array"]); } ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 3 (if user chooses to adjust item quantity) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != "") { // execute some code $item_to_adjust = $_POST['item_to_adjust']; $quantity = $_POST['quantity']; $quantity = preg_replace('#[^0-9]#i', '', $quantity); // filter everything but numbers if ($quantity >= 100) { $quantity = 99; } if ($quantity < 1) { $quantity = 1; } if ($quantity == "") { $quantity = 1; } $i = 0; foreach ($_SESSION["cart_array"] as $each_item) { $i++; while (list($key, $value) = each($each_item)) { if ($key == "item_id" && $value == $item_to_adjust) { // That item is in cart already so let's adjust its quantity using array_splice() array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $item_to_adjust, "quantity" => $quantity))); } // close if condition } // close while loop } // close foreach loop } ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 4 (if user wants to remove an item from cart) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] != "") { // Access the array and run code to remove that array index $key_to_remove = $_POST['index_to_remove']; if (count($_SESSION["cart_array"]) <= 1) { unset($_SESSION["cart_array"]); } else { unset($_SESSION["cart_array"]["$key_to_remove"]); sort($_SESSION["cart_array"]); } } ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 5 (render the cart for the user to view on the page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $cartOutput = ""; $cartTotal = ""; $pp_checkout_btn = ''; $product_id_array = ''; if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { $cartOutput = "<h2 align='center'>Your shopping cart is empty</h2>"; } else { // Start PayPal Checkout Button $pp_checkout_btn .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="[email protected]">'; // Start the For Each loop $i = 0; foreach ($_SESSION["cart_array"] as $each_item) { $item_id = $each_item['item_id']; $sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1"); while ($row = mysql_fetch_array($sql)) { $product_name = $row["product_name"]; $price = $row["price"]; $details = $row["details"]; } $pricetotal = $price * $each_item['quantity']; $cartTotal = $pricetotal + $cartTotal; setlocale(LC_MONETARY, "en_US"); $pricetotal = money_format("%10.2n", $pricetotal); <ERROR HERE> [Fatal error: Call to undefined function money_format() in D:\xampp\htdocs\Anonymous1\cart.php] // Dynamic Checkout Btn Assembly $x = $i + 1; $pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '"> <input type="hidden" name="amount_' . $x . '" value="' . $price . '"> <input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"> '; // Create the product array variable $product_id_array .= "$item_id-".$each_item['quantity'].","; // Dynamic table row assembly $cartOutput .= "<tr>"; $cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="40" height="52" border="1" /></td>'; $cartOutput .= '<td>' . $details . '</td>'; $cartOutput .= '<td>$' . $price . '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"> <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /> <input name="adjustBtn' . $item_id . '" type="submit" value="change" /> <input name="item_to_adjust" type="hidden" value="' . $item_id . '" /> </form></td>'; //$cartOutput .= '<td>' . $each_item['quantity'] . '</td>'; $cartOutput .= '<td>' . $pricetotal . '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>'; $cartOutput .= '</tr>'; $i++; } setlocale(LC_MONETARY, "en_US"); $cartTotal = money_format("%10.2n", $cartTotal); $cartTotal = "<div style='font-size:18px; margin-top:12px;' align='right'>Cart Total : ".$cartTotal." USD</div>"; // Finish the Paypal Checkout Btn $pp_checkout_btn .= '<input type="hidden" name="custom" value="' . $product_id_array . '"> <input type="hidden" name="notify_url" value="https://www.yoursite.com/storescripts/my_ipn.php"> <input type="hidden" name="return" value="https://www.yoursite.com/checkout_complete.php"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="cbt" value="Return to The Store"> <input type="hidden" name="cancel_return" value="https://www.yoursite.com/paypal_cancel.php"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="currency_code" value="USD"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!"> </form>'; } ?> <!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>Your Cart</title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("template_header.php");?> <div id="pageContent"> <div style="margin:24px; text-align:left;"> <br /> <table width="100%" border="1" cellspacing="0" cellpadding="6"> <tr> <td width="18%" bgcolor="#C5DFFA"><strong>Product</strong></td> <td width="45%" bgcolor="#C5DFFA"><strong>Product Description</strong></td> <td width="10%" bgcolor="#C5DFFA"><strong>Unit Price</strong></td> <td width="9%" bgcolor="#C5DFFA"><strong>Quantity</strong></td> <td width="9%" bgcolor="#C5DFFA"><strong>Total</strong></td> <td width="9%" bgcolor="#C5DFFA"><strong>Remove</strong></td> </tr> <?php echo $cartOutput; ?> <!-- <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> --> </table> <?php echo $cartTotal; ?> <br /> <br /> <?php //echo $pp_checkout_btn; ?> <br /> <br /> <a href="cart.php?cmd=emptycart">Click Here to Empty Your Shopping Cart</a> </div> <br /> </div> <?php include_once("template_footer.php");?> </div> </body> </html>
-
stil error im using xampp. im not very good at php
-
how about this Fatal error: Call to undefined function money_format() in D:\xampp\htdocs\Anonymous1\cart.php on line 120 while ($row = mysql_fetch_array($sql)) { $product_name = $row["product_name"]; $price = $row["price"]; $details = $row["details"]; } $pricetotal = $price * $each_item['quantity']; $cartTotal = $pricetotal + $cartTotal; setlocale(LC_MONETARY, "en_US"); $pricetotal = money_format("%10.2n", $pricetotal); <<<< ERROR AGAIN // Dynamic Checkout Btn Assembly $x = $i + 1; $pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '"> <input type="hidden" name="amount_' . $x . '" value="' . $price . '"> <input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"> '; // Create the product array variable $product_id_array .= "$item_id-".$each_item['quantity'].","; // Dynamic table row assembly $cartOutput .= "<tr>"; $cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="40" height="52" border="1" /></td>';
-
<<<<----- screenshot here! <?php // This file is www.developphp.com curriculum material // Written by Adam Khoury January 01, 2011 // http://www.youtube.com/view_play_list?p=442E340A42191003 // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Check to see the URL variable is set and that it exists in the database if (isset($_GET[id'])) { // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $id = preg_replace([^0-9]', '', $_GET["id"]); <<<<THIS IS THE PROBLEM I CANNOT FIX IT // Use this var to check to see if this ID exists, if yes then get the product // details, if no then exit this script and give message why $sql = mysql_query(SELECT * FROM products WHERE id='$id' LIMIT 1); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { // get all the product details while($row = mysql_fetch_array($sql)){ $product_name = $row["product_name"]; $price = $row["price"]; $details = $row["details"]; $category = $row["category"]; $subcategory = $row["subcategory"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); } } else { echo "That item does not exist."; exit(); } } else { echo "Data to render this page is missing."; exit(); } mysql_close(); ?> <!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><?php echo $product_name; ?></title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("template_header.php");?> <div id="pageContent"> <table width="100%" border="0" cellspacing="0" cellpadding="15"> <tr> <td width="19%" valign="top"><img src="inventory_images/<?php echo $id; ?>.jpg" width="142" height="188" alt="<?php echo $product_name; ?>" /><br /> <a href="inventory_images/<?php echo $id; ?>.jpg">View Full Size Image</a></td> <td width="81%" valign="top"><h3><?php echo $product_name; ?></h3> <p><?php echo "$".$price; ?><br /> <br /> <?php echo "$subcategory $category"; ?> <br /> <br /> <?php echo $details; ?> <br /> </p> <form id="form1" name="form1" method="post" action="cart.php"> <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" /> <input type="submit" name="button" id="button" value="Add to Shopping Cart" /> </form> </td> </tr> </table> </div> <?php include_once("template_footer.php");?> </div> </body> </html>