Jump to content

hance2105

Members
  • Posts

    121
  • Joined

  • Last visited

Everything posted by hance2105

  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.
  13. i added b.prod_id to line $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"); it solved out part of my problem in the second part of the code, when you click on edit beside each product being displayed, a page is displayed where product name, product brand and price is displayed. mine is not displaying at all. any help to sort this out please?
  14. hello guys, i have 2 tables - tblproduct and tblretprod. prod_id is common in both. i am retrieving records from the tables to display with edit and delete options beside each record displayed. i created an update.php and updprod.php (for edit). update.php <!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>Update/Delete Product</title> <?php include_once("db_connect.php"); $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"); ?> </head> <body> <?php echo "<table width='80%' border=0>"; echo "<tr bgcolor='#CCCCCC'>";echo "<td>Product</td>";echo "<td>Brand</td>";echo "<td>Price</td>";echo "<td>Action</td>";echo "</tr>"; while($res=mysql_fetch_array($result)){ echo "<tr>";echo "<td>".$res['prod_name']."</td>";echo "<td>".$res['prod_brand']."</td>";echo "<td>".$res['prod_price']."</td>"; echo "<td><a href=\"edit.php?prod_id=$res[prod_id]\">Edit</a> | <a href=\"delete.php?prod_id=$res[prod_id]\">Delete</a></td>";} echo "</table>";?> </body></html> </body></html> error message being displayed for code above is - notice: Notice: Undefined index: prod_id in C:\wamp\www\buysmart_site\update.php on line 36 upd_prod.php 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 proc_price='$prod_price' WHERE prod_id=$prod_id"); //redirectig to the display page. In our case, it is index.php//header("Location: index.php");}}?><?php//for displaying data of this particular data //getting id from url$prod_id = $_GET['prod_id']; //selecting data associated with this particular 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"); while($res=mysql_fetch_array($result)){$prod_name = $res['prod_name'];$prod_brand = $res['prod_brand'];$prod_price = $res['prod_price'];}?><html><title>Edit Product</title><body><a href="#">Home</a><br/><br/><form name="edit" method="post" action="edit.php"><table border="0"> <tr> <td>Product Name</td> <td> <input disabled="disabled" type="text" name="prod_name" value=<?php echo $prod_name;?>> </td> </tr> <tr> <td>Brand</td> <td> <input disabled="disabled" type="text" 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;?>> </td> </tr><tr> <td><input type="hidden" name="prod_id" value=<?php echo $_GET['prod_id'];?>> </td> <td><input type="submit" name="update" value="Update"></td> </tr></table></form> </body></html> same error message as above can anyone please help me in defining the prod_id?
  15. well guys i managed to sort out the issue with code above. the <td> thing was not properly formatted. now working great. thanks to everyone who helped...
  16. hello guys, i tried below code as well but this time the drop down is not being displayed and am having an undefined variable for selected_product it would be of great help if i knew where the issue is and how to sort it out...either with the code below or the previous one i provided thank you....am stuck with that since some days now and would like to sort this out please <!-- you beginning HTML --> <?php include('db_connect.php'); $prod_name = isset($_GET['prod_name'])?$_GET['prod_name']:""; $sql = "select p.prod_name, pr.prod_price from tblproduct p INNER JOIN tblretprod pr ON p.prod_id = pr.prod_id"; $result = mysql_query($sql); if(mysql_num_rows($result) < 1) {} //No records, do something (exit, die, return, whatever) ?> <!-- Continue your HTML --> <?php while($row = mysql_fetch_array($result){ if($row['prod_name'] == $prod_name) { $selected_product = $row; echo "<option selected value='".$row['0']."'>".$row['0']." </option>"; } else { echo "<option value=\"".$row['0']."\">".$row['0']."</option>"; } } ?> <!-- Continue your HTML --> <td><input type="text" name="prod_price" id="prod_price" value = "<?php print $selected_product['prod_price'] ?>"/></td> <!-- Rest of HTML -->
  17. how can i amend the codes to have the required display please?
  18. <!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>Update product</title> <SCRIPT language=JavaScript>function reload(form){var val=form.prod_name.options[form.prod_name.options.selectedIndex].value;//var description1=form.description.value;self.location='upd_prod.php?prod_name=' + val;//+'&description=' +description1;} </script> <link href="CSS/update.css" rel="stylesheet" type="text/css" /></head> <body> <?php include('db_connect.php'); @$prod_name=$_GET['prod_name']; $query=mysql_query("select p.prod_name, pr.prod_price from tblproduct p INNER JOIN tblretprod pr ON p.prod_id = pr.prod_id"); //$query1=mysql_query("select prod_price from tblretprod where prod_id='$prod_id'"); //$row=mysql_num_rows($query); ?> <div id="stylized" class="myform"> <form id="form" name="upd_prod" method="post" action="updprod.php"> <h2 align="center"><b>- Update Product -</b></h2> <table width="1000" border="0"> <tr> <td><div align="right">Product Name</div></td> <td> <?PHP echo "<select name='prod_name' onchange=\"reload(this.form)\"><option value=''>select one</option>";while($row1 = mysql_fetch_array ($query)) { if($row1['0']==@$prod_name){echo "<option selected value='".$row1['0']."'>".$row1['0']."</option>";}else{echo "<option value=\"".$row1['0']."\">".$row1['0']."</option>";}}echo "</select>";?> </td> </tr> <tr> <td><div align="right">Product Price (MRU)</div></td> <td><input type="text" name="prod_price" id="prod_price" value = "<?PHP print $row1['prod_price'] ?>"/></td> </tr></table> <p align="center"> <input type="submit" class="button" name="update" id="update" value="<-- Update product -->" /></p> </form> </div> </body></html>
  19. Yes i know that. I did the necessary changes and used $row1 for the prod_price. Still nothing is displayed upon selecting the product name.
  20. any help is welcome to let me know where am erring. i looked at the code several times but still dnt know where the issue is...if i sort this out i can carry on with other works...this will unlock mostly everything in my project
  21. I tried everything so far but still this is a pain. I looked at the code over and over again but still can't know why the error message is being displayed and the price is not being populated. If it gets populated, i can proceed with price updates of the product being selected.
×
×
  • 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.