Jump to content

thelee

Members
  • Posts

    60
  • Joined

  • Last visited

thelee's Achievements

Member

Member (2/5)

0

Reputation

  1. thelee

    multi query

    sorry pysco, i dont think your way is much better,its my system and i know how it works.dont post here if you just want to increase your posts. this forum getting sucks. seriously. lot of admin doesn't help.btw i already solve my problem by myself. thank you.
  2. thelee

    multi query

    i tried like this and its not working. <? include("connection.php"); $id_product=$_GET["pid"]; $sql = "INSERT INTO `order2` SELECT * FROM `order` WHERE id_product='$id_product'"; $sql_delete="DELETE FROM `order` WHERE id_product='$id_product'"; $result=mysql_query or die("Error in sql due to ".mysql_error()); if ($result) header("Location: order_list.php"); ?> the purpose of two tables is one for admin and one for staff. when staff delete the data,it will send to the admin.
  3. thelee

    multi query

    How i can delete record from table `order` and move it to `order2` the table `order2` structure is exactly like table `order`.here is the code that i made. <? include("connection.php"); $id_product=$_GET["pid"]; $sql_delete="DELETE FROM `order` WHERE id_product='$id_product'"; $result=mysql_query($sql_delete) or die("Error in sql due to ".mysql_error()); if ($result) header("Location: order_list.php"); ?>
  4. how i can make the query can define all the value? i thought by add this code. $name=$_POST["name"]; $quantity=$_POST["quantity"]; $price=$_POST["price"];
  5. ops,sorry.i have changed it, data is recorded but the data is wrong.i dont know why the data is like this
  6. fastsol.i have put it and this is the error: Notice: Undefined index: name in C:\xampp\htdocs\emakengku\cart.phpon line 5 Notice: Undefined index: price in C:\xampp\htdocs\emakengku\cart.phpon line 7 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 ('name', 'quantity', 'price') values('', 'Array', '')' at line 1
  7. i have put `backticks` and the result still same,
  8. i have follow a video how to make a shopping cart, the video didnt teach me how to insert all confirmed data into table,so i try to make it by myself,and im still newbie in php. so after i make some changes at the cart.php, its echo sucess,but no data inserted into table.can someone show me what is my mistake. here is the code: index2.php <? session_start(); error_reporting(E_ALL); require("connection.php"); if(isset($_GET['page'])){ $pages=array("products", "cart"); if(in_array($_GET['page'], $pages)) { $_page=$_GET['page']; }else{ $_page="products"; } }else{ $_page="products"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> <link rel="stylesheet" href="style2.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script> <script type="text/javascript"> $(function() { }); </script> </head> <body> <div id="container"> <div id="main"> <?php require($_page.".php"); ?> </div> <div id="sidebar"> <h1>Cart</h1> <?php if(isset($_SESSION['cart'])){ $sql="SELECT * FROM products WHERE id_product IN ("; foreach($_SESSION['cart'] as $id => $value) { $sql.=$id.","; } $sql=substr($sql, 0, -1).") ORDER BY name ASC"; $query=mysql_query($sql); while($row=mysql_fetch_array($query)){ ?> <p><?php echo $row['name'] ?> x <?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?></p> <?php } ?> <hr /> <a href="index2.php?page=cart">Go to Cart</a> <?php }else{ echo "<p>Your Cart is empty</p>"; } ?> </div> </div> </body> products.php <?php if(isset($_GET['action']) && $_GET['action']=="add"){ $id=intval($_GET['id']); if(isset($_SESSION['cart'][$id])){ $_SESSION['cart'][$id]['quantity']++; }else{ $sql_s="SELECT * FROM products WHERE id_product={$id}"; $query_s=mysql_query($sql_s); if(mysql_num_rows($query_s)!=0){ $row_s=mysql_fetch_array($query_s); $_SESSION['cart'][$row_s['id_product']]=array( "quantity" => 1, "price" => $row_s['price'] ); }else{ $message="This product id it's invalid!"; } } } ?> <h1>Product List</h1> <?php if(isset($message)){ echo "<h2>$message</h2>"; } ?> <table> <tr> <th>Name</th> <th>Description</th> <th>Price</th> <th>Action</th> </tr> <?php $sql="SELECT * FROM products ORDER BY name ASC"; $query=mysql_query($sql); while ($row=mysql_fetch_array($query)) { ?> <tr> <td><?php echo $row['name'] ?></td> <td><?php echo $row['description'] ?></td> <td>RM <?php echo $row['price'] ?></td> <td><a href="index2.php?page=products&action=add&id=<?php echo $row['id_product'] ?>">Add To Cart</a></td> </tr> <?php } ?> </table> cart.php <?php error_reporting(E_ALL ^ E_NOTICE); require("connection.php"); if(isset($_POST['submit2'])) { $name=$_POST["name"]; $quantity=$_POST["quantity"]; $price=$_POST["price"]; $sql_insert = "INSERT INTO order ('name', 'quantity', 'price') values('$name', '$quantity', '$price')"; mysql_query($sql_insert); echo "sucess!"; } if(isset($_POST['submit'])){ foreach($_POST['quantity'] as $key => $val) { if($val==0) { unset($_SESSION['cart'][$key]); }else{ $_SESSION['cart'][$key]['quantity']=$val; } } } ?> <a href="index2.php?page=products">Go back to product page</a> <h1>View Cart</h1> <form method="post" action="index2.php?page=cart"> <table> <tr> <th>Name</th> <th>Quantity</th> <th>Price</th> <th>Item Price</th> </tr> <?php $sql="SELECT * FROM products WHERE id_product IN ("; foreach($_SESSION['cart'] as $id => $value) { $sql.=$id.","; } $sql=substr($sql, 0, -1).") ORDER BY name ASC"; $query=mysql_query($sql); $totalprice=0; while($row=mysql_fetch_array($query)){ $subtotal=$_SESSION['cart'][$row['id_product']]['quantity']*$row['price']; $totalprice+=$subtotal; ?> <tr> <td><?php echo $row['name'] ?></td> <td><input type="text" name="quantity[]" size="5" value="<?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?>"</td> <td>RM <?php echo $row['price'] ?></td> <td>RM <?php echo $_SESSION['cart'][$row['id_product']]['quantity']*$row['price'] ?></td> </tr> <?php } ?> <tr> <td>Total Price: <?php echo $totalprice ?></td> </tr> </table> <button type="submit" name="submit"> Update Cart</button> <button type="submit" name="submit2"> Update Cart</button> </form> <br /> <p> To remove an item,set the quantity to 0</p>
  9. i have define.it still give me error.here is the code that i have change. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); require("connection.php"); if(isset($_POST['submit2'])) $name=$_POST["name"]; $quantity=$_POST["quantity"]; $price=$_POST["price"]; $sql_insert = "INSERT INTO order ('name', 'quantity', 'price') values ('name', 'quantity', 'price')"; echo "sucess!"; if(isset($_POST['submit'])){ foreach($_POST['quantity'] as $key => $val) { if($val==0) { unset($_SESSION['cart'][$key]); }else{ $_SESSION['cart'][$key]['quantity']=$val; } } } ?> <a href="index2.php?page=products">Go back to product page</a> <h1>View Cart</h1> <form method="post" action"index2.php?page=cart"> <table> <tr> <th>Name</th> <th>Quantity</th> <th>Price</th> <th>Item Price</th> </tr> <?php $sql="SELECT * FROM products WHERE id_product IN ("; foreach($_SESSION['cart'] as $id => $value) { $sql.=$id.","; } $sql=substr($sql, 0, -1).") ORDER BY name ASC"; $query=mysql_query($sql); $totalprice=0; while($row=mysql_fetch_array($query)){ $subtotal=$_SESSION['cart'][$row['id_product']]['quantity']*$row['price']; $totalprice+=$subtotal; ?> <tr> <td><?php echo $row['name'] ?></td> <td><input type="text" name="quantity[<?php echo $row['id_product'] ?>]" size="5" value="<?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?>"</td> <td>RM <?php echo $row['price'] ?></td> <td>RM <?php echo $_SESSION['cart'][$row['id_product']]['quantity']*$row['price'] ?></td> </tr> <?php } ?> <tr> <td>Total Price: <?php echo $totalprice ?></td> </tr> </table> <button type="submit" name="submit"> Update Cart</button> <button type="submit" name="submit2"> Update Cart</button> </form> <br /> <p> To remove an item,set the quantity to 0</p> here is the error Notice: Undefined index: name in C:\xampp\htdocs\emakengku\cart.phpon line 7 Notice: Undefined index: quantity inC:\xampp\htdocs\emakengku\cart.php on line 8 Notice: Undefined index: price in C:\xampp\htdocs\emakengku\cart.phpon line 9
  10. thanks mac.i have change the cart.php like this,its working fine i think,but i get this error when i clicked the submit2 button. what is my mistake now ? <?php error_reporting(E_ALL); ini_set('display_errors', '1'); require("connection.php"); if(isset($_POST['submit2'])){ mysql_query("INSERT INTO order (name, quantity, price) VALUES('$name', '$quantity', '$price' ) ") or die(mysql_error()); echo "data inserted"; } if(isset($_POST['submit'])){ foreach($_POST['quantity'] as $key => $val) { if($val==0) { unset($_SESSION['cart'][$key]); }else{ $_SESSION['cart'][$key]['quantity']=$val; } } } ?> <a href="index2.php?page=products">Go back to product page</a> <h1>View Cart</h1> <form method="post" action"index2.php?page=cart"> <table> <tr> <th>Name</th> <th>Quantity</th> <th>Price</th> <th>Item Price</th> </tr> <?php $sql="SELECT * FROM products WHERE id_product IN ("; foreach($_SESSION['cart'] as $id => $value) { $sql.=$id.","; } $sql=substr($sql, 0, -1).") ORDER BY name ASC"; $query=mysql_query($sql); $totalprice=0; while($row=mysql_fetch_array($query)){ $subtotal=$_SESSION['cart'][$row['id_product']]['quantity']*$row['price']; $totalprice+=$subtotal; ?> <tr> <td><?php echo $row['name'] ?></td> <td><input type="text" name="quantity[<?php echo $row['id_product'] ?>]" size="5" value="<?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?>"</td> <td>RM <?php echo $row['price'] ?></td> <td>RM <?php echo $_SESSION['cart'][$row['id_product']]['quantity']*$row['price'] ?></td> </tr> <?php } ?> <tr> <td>Total Price: <?php echo $totalprice ?></td> </tr> </table> <button type="submit" name="submit"> Update Cart</button> <button type="submit" name="submit2"> Update Cart</button> </form> <br /> <p> To remove an item,set the quantity to 0</p> here is the error: Notice: Undefined variable: name inC:\xampp\htdocs\emakengku\cart.php on line 6 Notice: Undefined variable: quantity inC:\xampp\htdocs\emakengku\cart.php on line 6 Notice: Undefined variable: price in C:\xampp\htdocs\emakengku\cart.phpon line 6 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 (name, quantity, price) VALUES('', '', '' )' at line 1
  11. wew,its much complicated than i expected. its mean i must change to if(isset($_POST['submit'2])){ header:location...} ?
  12. i have add the code.still same,it do not show any error.when i click the submit2 button,nothing happen.when i clicked submit button,it will update the cart.
  13. i have modified the cart.php to insert data into table,but it dont have and error and dont insert the data into table.can help me ? here is the cart.php <?php error_reporting(E_ALL); require("connection.php"); if(isset($_POST['submit'])){ foreach($_POST['quantity'] as $key => $val) { if($val==0) { unset($_SESSION['cart'][$key]); }else{ $_SESSION['cart'][$key]['quantity']=$val; if(isset($_POST['submit2'])){ mysql_query("INSERT INTO order (name, quantity, price) VALUES('$name', '$count', '$price' ) ") or die(mysql_error()); echo "data inserted"; } } } } ?> <a href="index2.php?page=products">Go back to product page</a> <h1>View Cart</h1> <form method="post" action"index2.php?page=cart"> <table> <tr> <th>Name</th> <th>Quantity</th> <th>Price</th> <th>Item Price</th> </tr> <?php $sql="SELECT * FROM products WHERE id_product IN ("; foreach($_SESSION['cart'] as $id => $value) { $sql.=$id.","; } $sql=substr($sql, 0, -1).") ORDER BY name ASC"; $query=mysql_query($sql); $totalprice=0; while($row=mysql_fetch_array($query)){ $subtotal=$_SESSION['cart'][$row['id_product']]['quantity']*$row['price']; $totalprice+=$subtotal; ?> <tr> <td><?php echo $row['name'] ?></td> <td><input type="text" name="quantity[<?php echo $row['id_product'] ?>]" size="5" value="<?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?>"</td> <td>RM <?php echo $row['price'] ?></td> <td>RM <?php echo $_SESSION['cart'][$row['id_product']]['quantity']*$row['price'] ?></td> </tr> <?php } ?> <tr> <td>Total Price: <?php echo $totalprice ?></td> </tr> </table> <button type="submit" name="submit"> Update Cart</button> <button type="submit" name="submit2"> Update Cart</button> </form> <br /> <p> To remove an item,set the quantity to 0</p>
×
×
  • 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.