Jump to content

hance2105

Members
  • Posts

    121
  • Joined

  • Last visited

hance2105's Achievements

Member

Member (2/5)

0

Reputation

  1. hello, i have below code and i need to change the status to inactive when i press the delete button. it happens that when i use the code below, the status does not change at all. can anyone tell me where am having an error in the code? <?php session_start(); include_once("db_connect.php"); if(isset($_POST['delete'])) { $prod_id=$_POST['prod_id']; $prod_name=$_POST['prod_name']; $prod_brand=$_POST['prod_brand']; $prod_desc=$_POST['prod_desc']; $prod_w_c=$_POST['prod_w_c']; //updating the table $result=mysql_query("UPDATE tblproduct SET status='inactive' WHERE prod_id='".$prod_id."';"); header("Location: del_updprod.php"); } ?> <?php $prod_id = $_GET['prod_id']; $result=mysql_query("SELECT * FROM tblproduct where prod_id = ".$prod_id." AND status = 'active'") or die(mysql_error()); ?> <html> <title>Delete Product</title> <body background="Images/contentbg.jpg"> <a href="del_updprod.php"><img src="Images/back button.png" width="100" /></a> <br/><br/> <form name="edit" method="post" action="del_prod.php"> <table align="center" border="0"> <?php while($res=mysql_fetch_array($result)) { $prod_name=$res['prod_name']; $prod_brand=$res['prod_brand']; $prod_desc=$res['prod_desc']; $prod_w_c=$res['prod_w_c']; ?> <tr> <td>Product Name</td> <td> <input type="text" name="prod_name" value = "<?php echo $prod_name;?>"> </td> </tr> <tr> <td>Product Brand</td> <td> <input type="text" name="prod_brand" value = "<?php echo $prod_brand;?>"> </td> </tr> <tr> <td>Product Description</td> <td> <textarea rows="5" cols="50" name="ret_city"><?php echo $prod_desc;?></textarea> </td> </tr> <tr> <td>Product Weight/Capacity</td> <td> <input type="text" name="prod_w_c" value = "<?php echo $prod_w_c;?>"> </td> </tr> <?php } ?> <tr> <td><input type="submit" name="delete" value="Delete"></td> </tr> </table> </form> </body> </html>
  2. hello guys i have created the below codes. the first one is the mysql select statement which works fine when i echo. the second one is an html/css table i created. i am stuck to the point where i can merge both of them so that i get a nice display and the total price of the products are calculated in each column. the first code selects product name, retailer name and product price from 5 tables. using the echo codes i can display the records in columns. code for mysql select statement <?php session_start(); include('db_connect.php'); $username = $_SESSION['username']; $user = mysql_fetch_assoc(mysql_query("select user_id from tbllogin where username = '{$username}'")); $query = mysql_query("SELECT * FROM tblfav_ret a, tblretailer b, tblretprod c, tblproduct d, tblfavourites eWHERE a.ret_id = b.ret_idAND b.user_id = c.user_idAND c.prod_id = d.prod_idAND d.prod_id = e.prod_idAND a.user_id = '{$user['user_id']}'"); $num = mysql_num_rows($query); if($num>0){ echo "<center><table bgcolor='grey' width='80%' border=0>"; echo "<tr bgcolor='#CCCCCC'>";echo "<td><b><center>Name</td>";echo "<td><b><center>Retailer</td>";echo "<td><b><center>Price</td>";echo "</tr>"; while($row = mysql_fetch_assoc($query)){ extract($row); echo "<tr>"; echo "<td style='text-align: center;'>".$row['prod_name']."</td>"; echo "<td style='text-align: center;'>".$row['ret_name']."</td>";echo "<td style='text-align: center;'>".$row['prod_price']."</td>";echo "</tr>"; }echo "</table>";} ?> i further created this html/css table which displays smthng like this product name <retailer_name> <retailer_name> <retailer_name> <retailer_name> prod_1 price1 price2 price3 price4 prod_2 price1 price2 price3 price4 total <total_price> <total_price> <total_price> <total_price> <html> <body> <div id="myfavourites"> <table class="fav_tbl"> <thead> <tr> <th scope="col">Product</th> <th scope="col">Retailer 1</th> <th scope="col">Retailer 2</th> <th scope="col">Retailer 3</th> <th scope="col">Retailer 4</th> </tr> </thead> <tfoot> <tr> <th scope="row">Total per month</th> <td>Total 1</td> <td>Total 2</td> <td>Total 3</td> <td>Total 4</td> </tr> </tfoot> </table> </div> </body> </html> the help i need is to make the display in the html/css table and calculation of total price of products listed
  3. hello guys, i am selecting records from 3 tables (2 more to come later) but when i echo the result, no error messages are displayed and no records are being retrieved. please verify the code below and let me know where i erred. <?php session_start(); include('db_connect.php'); $username = $_SESSION['username']; $user = mysql_fetch_assoc(mysql_query("select user_id from tbllogin where username = '{$username}'")); $sql = ("SELECT prod_id FROM tblfavourites WHERE user_id = '$user[user_id]'"); $sql1 = ("SELECT ret_id FROM tblfav_ret WHERE user_id = '$user[user_id]'"); $query = mysql_query("SELECT p.prod_name, rp.prod_price, r.ret_nameFROM tblproduct AS pLEFT JOIN tblretprod AS rp ON (rp.prod_id = p.prod_id)LEFT JOIN tblretailer AS r ON (r.user_id = rp.user_id)WHERE p.prod_id IN ($sql) AND r.ret_id IN ($sql1)"); $row = mysql_fetch_row($query); echo $row['prod_name']; ?>
  4. i have the following tables tblretprod - id, user_id, prod_id, prod_price tblproduct - prod_id, prod_name, prod_brand, prod_desc, prod_photo tblfavourites - fav_id, prod_id, user_id tblfav_ret - id, user_id, ret_id tblretailer - ret_id, user_id, ret_name, ret_address, ret_phone, ret_fax
  5. i will explain the scenario as i don't know how to do it and i don't know if someone ever did it before. I am creating a price comparison website. The customers can add products as their favourites from a list of products. They can also add 4 retailers as their favourites. Both will be stored in 2 tables - tblfavourites and tblfav_retailer. All the retailers have set different prices for the products. I want to create a table displaying the products set as favourites by the customers and the 4 retailers. Under each retailer, will be displayed the price of the product they set. The total price of products by each retailer will be displayed at the bottom. Can anyone help me out in creating that?
  6. now the issue is that there is a product details button for each product display. when i click on my product details button, details of all products are displayed and not the details of the product i clicked. Any help in solving that please?
  7. Oops my mistake...i found the error...sorry guys error was in the select statement
  8. hey guys, i have created a page called prod_det.php. the page displays the details of the product. below is the code. but it is not working. error message being received when i click the details button is Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean <?php session_start(); ?> <!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>Product</title> <link href="CSS/product.css" rel="stylesheet" type="text/css" /> </head> <body> <?php //Create the connection and select the DB include('db_connect.php'); // Select records from the DB $query = "SELECT p.prod_name, p.prod_photo, pr.prod_price, pr.prod_desc, pr.prod_brand, pr.prod_w_c FROM tblproduct p INNER JOIN tblretprod pr ON p.prod_id = pr.prod_id"; $result = mysql_query($query); // Display records from the table ?> <?php while ($row = mysql_fetch_array($result)): ?> <div class="prod_box_big"> <div class="top_prod_box_big"></div> <div class="center_prod_box_big"> <div class="product_img_big"><?= '<img height="100" width="100" src="Images/Products/'.$row['prod_photo'].'"/>'; ?> <div class="thumbs"><?= $row['prod_desc']; ?></div> </div> <div class="details_big_box"> <div class="product_title_big"><?= $row['prod_name']; ?></div> <div class="specifications"> Brand: <span class="blue"><?= $row['prod_brand']; ?></span><br /> Quantity: <span class="blue"><?= $row['prod_w_c']; ?></span><br /> Price include <span class="blue">TVA</span><br /> </div> <div class="prod_price_big"><span class="reduce"><?= $row['prod_price']; ?></span> <span class="price">%promo%</span></div> <a href="#" class="addtocart">add to fav</a> <a href="#" class="compare">compare</a> </div> </div> <div class="bottom_prod_box_big"></div> </div> <?php endwhile; ?> </body> </html>
  9. i managed to solve it. thanks...
  10. i managed to solve the issue but now all products are being displayed instead of the one beside which i clicked the edit link. find below the new codes include_once("db_connect.php"); if(isset($_POST['update'])){$prod_id = $_POST['prod_id']; $prod_name=$_POST['prod_name'];$prod_brand=$_POST['prod_brand'];$prod_price=$_POST['prod_price']; // checking empty fieldif(empty($prod_price)){//if name field is emptyif(empty($prod_price)){echo "<font color='red'>Price field is empty.</font><br/>";} } else{ //updating the table//$result=mysql_query("UPDATE tblretprod SET prod_price='$prod_price' WHERE prod_id=$prod_id");$result=mysql_query("UPDATE tblretprod SET prod_price='".$prod_price."' WHERE prod_id='".$prod_id."';"); //redirectig to the display page. In our case, it is index.phpheader("Location: update.php");}}?><?php $prod_id = $_GET['prod_id']; $result=mysql_query("SELECT a.prod_name, a.prod_brand, b.prod_price FROM tblproduct a, tblretprod b where a.prod_id = b.prod_id") or die(mysql_error()); ?><html><title>Edit Product</title><body><a href="#">Home</a><br/><br/><form name="edit" method="post" action="updprod.php"><table border="0"><?phpwhile($res=mysql_fetch_array($result)){$prod_name = $res['prod_name'];$prod_brand = $res['prod_brand'];$prod_price = $res['prod_price']; ?> <tr> <td>Product Name</td> <td> <input type="text" disabled="disabled" name="prod_name[]" value="<?php echo $prod_name;?>"> </td> </tr> <tr> <td>Brand</td> <td> <input type="text" disabled="disabled" name="prod_brand[]" value="<?php echo $prod_brand;?>"> </td> </tr><tr> <td>Product Price</td> <td> <input type="text" name="prod_price[]" value="<?php echo $prod_price;?>"> <input type="hidden" name="prod_id[]" value="<?php echo $_GET['prod_id'];?>"> </td> </tr> <?php } ?> <tr> <td><input type="submit" name="update" value="Update"></td> </tr></table></form> </body></html>
  11. i just tested the codes and the price is being updated accordingly but the product name, brand and price being defaulted is the last one inserted. it is not displaying the name, brand and price of the product beside which i clicked the edit. can i know why the last product details are being displayed? what do i need to change in my codes?
  12. ok i will clarify things here. 1. i added "b.prod_id" to the line and it solved the first issue. 2. on clicking on edit on the page where the list of products is displayed, the text fields are not being populated with the details of the product where i clicked the edit. i forgot to change the file name. it is updprod.php indeed.
×
×
  • 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.