PHP - Getting Product List From Two Tables In The Database.
Hi there i have a big issues which is starting to cause me lots of stress. I have two tables one which is products and contains the following below and the other which is additionalCategories which the contains is also below.
products id name image1 image2 image3 image4 image5 description department category subcategory Price additonalCategories id departmentID categoryID subcategoryID productID i have made a products upload script to my site where i can add products too it saves the category and subcategory id's in the fields above then if i wish to add the product to additional categories i do so and again this adds all the data to the addiotnalCategories table. however i can seems to be able to display this on the view products page i tried the below code but get no luck Code: [Select] <?php session_start(); $username=$_SESSION['username']; include_once"../includes/db_connect.php"; $cat=$_GET['cat']; ?> <!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>Untitled Document</title> </head> <body> <?php $query("SELECT products.name AS name, products.price AS price, addtionalCategories.productID AS productID FROM products, addtionalCategories WHERE category='$cat' AND products.id = addtionalCategories.productID"); while($fetch=mysql_fetch_object($query)){ echo"$fetch->name"; } ?> </body> </html> i need a way in which on the page it check the category id then finds all the products that are saved in the additionalCategories table then to find the data saved in the products table such as the name and price etc please any help will be appreciated thank you for reading Similar TutorialsHello, I've created a page search to return results from my database inventory. On top of these results I would like to display a seperate list of five products not included in the search results but share the same sub_category_b (a column in my SQL table). Posted below is my primary query of the database. If anyone can help me out with this it would be appreciated. Code: [Select] $colname_product = "-1"; if (isset($_GET['title'])) { $colname_product = $_GET['title']; } mysql_select_db($database_inventory, $inventory); $query_product = sprintf("SELECT * FROM inventory WHERE item_name LIKE %s OR item_desc LIKE %s ", GetSQLValueString("%" . $colname_product . "%", "text"),GetSQLValueString("%" . $colname_product . "%", "text")); $product = mysql_query($query_product, $inventory) or die(mysql_error()); $row_product = mysql_fetch_assoc($product); I've fooled around with this one for some time and haven't come up with a clear cut answer. Thank you in advance! Hi, I am just wondering if there is any way that I can link Google Maps which will then link to my product stocklist - see attachment for what I am trying to achieve. Please let me know if this is possible. Thanks, I would like to customize my product-list page to display all my products in a grid with an ADD TO CART option for each product. That means i have two ADD TO CART button on the site, in productDetail.php there is a ADD TO CART button original from the tutorial, i need customize another ADD TO CART button on productList.php. Does anyone know how to accomplish this customization? . Please help because I am stuck with the coding for 3weeks Tutorial site: http://www.phpwebcommerce.com/plaincart/index.php productDetail.php: Code: [Select] <?php if (!defined('WEB_ROOT')) { exit; } $product = getProductDetail($pdId, $catId); // we have $pd_name, $pd_price, $pd_description, $pd_image, $cart_url extract($product); ?> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td align="center"><img src="<?php echo $pd_image; ?>" border="0" alt="<?php echo $pd_name; ?>" width="230" height="170"></td> <td valign="middle"> <strong><?php echo $pd_name; ?></strong><br> Price : <?php echo displayAmount($pd_price); ?><br> <?php // if we still have this product in stock // show the 'Add to cart' button if ($pd_qty > 0) { ?> <input type="button" name="btnAddToCart" value="Add To Cart >" onClick="window.location.href='<?php echo $cart_url; ?>';" class="addToCartButton"> <?php } else { echo 'Out Of Stock'; } ?> </td> </tr> <tr align="left"> <td colspan="2"><?php echo $pd_description; ?></td> </tr> </table> productList.php: Code: [Select] <?php if (!defined('WEB_ROOT')) { exit; } $productsPerRow = 2; $productsPerPage = 8; //$productList = getProductList($catId); $children = array_merge(array($catId), getChildCategories(NULL, $catId)); $children = ' (' . implode(', ', $children) . ')'; $sql = "SELECT pd_id, pd_name, pd_price, pd_thumbnail, pd_qty, c.cat_id FROM tbl_product pd, tbl_category c WHERE pd.cat_id = c.cat_id AND pd.cat_id IN $children ORDER BY pd_name"; $result = dbQuery(getPagingQuery($sql, $productsPerPage)); $pagingLink = getPagingLink($sql, $productsPerPage, "c=$catId"); $numProduct = dbNumRows($result); // the product images are arranged in a table. to make sure // each image gets equal space set the cell width here $columnWidth = (int)(100 / $productsPerRow); ?> <table width="100%" border="0" cellspacing="0" cellpadding="20"> <?php if ($numProduct > 0 ) { $i = 0; while ($row = dbFetchAssoc($result)) { extract($row); if ($pd_thumbnail) { $pd_thumbnail = WEB_ROOT . 'images/product/' . $pd_thumbnail; } else { $pd_thumbnail = WEB_ROOT . 'images/no-image-small.png'; } if ($i % $productsPerRow == 0) { echo '<tr>'; } // format how we display the price $pd_price = displayAmount($pd_price); echo "<td width=\"$columnWidth%\" align=\"center\"><a href=\"" . $_SERVER['PHP_SELF'] . "?c=$catId&p=$pd_id" . "\"><img src=\"$pd_thumbnail\" border=\"0\" width=\"230\" height=\"170\"><br>$pd_name</a><br>Price : $pd_price<br>"; // format display add to cart echo "<input type=\"button\" name=\"btnAddToCart\" value=\"Add To Cart >\" onClick=\"window.location.href='<?php echo $cart_url;?>';\" >"; // if the product is no longer in stock, tell the customer if ($pd_qty <= 0) { echo "<br>Out Of Stock"; } echo "</td>\r\n"; if ($i % $productsPerRow == $productsPerRow - 1) { echo '</tr>'; } $i += 1; } if ($i % $productsPerRow > 0) { echo '<td colspan="' . ($productsPerRow - ($i % $productsPerRow)) . '"> </td>'; } } else { ?> <tr><td width="100%" align="center" valign="center">No products in this category</td></tr> <?php } ?> </table> <p align="center"><?php echo $pagingLink; ?></p> Product-functions.php: Code: [Select] <?php require_once 'config.php'; /********************************************************* * PRODUCT FUNCTIONS **********************************************************/ /* Get detail information of a product */ function getProductDetail($pdId, $catId) { $_SESSION['shoppingReturnUrl'] = $_SERVER['REQUEST_URI']; // get the product information from database $sql = "SELECT pd_name, pd_description, pd_price, pd_image, pd_qty FROM tbl_product WHERE pd_id = $pdId"; $result = dbQuery($sql); $row = dbFetchAssoc($result); extract($row); $row['pd_description'] = nl2br($row['pd_description']); if ($row['pd_image']) { $row['pd_image'] = WEB_ROOT . 'images/product/' . $row['pd_image']; } else { $row['pd_image'] = WEB_ROOT . 'images/no-image-large.png'; } $row['cart_url'] = "cart.php?action=add&p=$pdId"; return $row; } ?> any help will be greatly appreciated This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=343748.0 I am wanting to create a basic product listing page for a product category called "Belts". My latest attempt was this, but I got an error: PHP Code: Code: [Select] $query = "select * from products"; $result = mysql_query($query); while($row=mysql_fetch_assoc($result)) { print ".$row['name'] where category = 'Belts'.$row['colour'] where category = 'Belts'"; } Quote PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING This is what my MySQL table looks like: http://i54.tinypic.com/2j1si8w.png I image what I am trying to do will print "Somename Black, ProductName2 Brown"? I'm not really interested in styling at the moment, I just want to see the PHP-MySQL work at the most basic level. I am unsure what the error cosde means. Can anyone see a fault in my code? hi i have generated a product list from a mysql table called product_list, once i enter a new product in to the table the product will be shown in the generated list and the list will grow and the table grows. and i want to allow user the edit/delete/save the products from the generated table, i have no idea how to do it and what is the algorithmic idea to do it so. here is the php and the html code. <!--Body container for creating a new product in to the list--> <div class="body_orderviewform"> <form name="form1" method="post" action="upload_file.php" enctype="multipart/form-data"> <p> <label for="user_id">User ID:</label> <input type="text" name="user_id" id="user_id"> <label for="customer_name">Customer Name:</label> <input type="text" name="customer_name" id="customer_name"> <label for="customer_family">Customer_family</label> <input type="text" name="customer_family" id="customer_family"> <label for="freelancer_name">Purchaser:</label> <input name="freelancer_name" type="text" id="freelancer_name"> <? if (isset($_COOKIE['picAdd'])) echo $_COOKIE['picAdd'];?> </p> <!------------------------------------------------------------------------------------------------------- for generating the list --> <div class="div.neworder_list" > <div class="div.neworder_listheader" align="center"> <table width="637" border="1" > <tr> <td width="193"><label for="link">link:</label> <label for="link_new"></label> <input type="text" name="link_new" id="link_new"></td> <td width="202"><label for="unitprice">Unit Price:</label> <label for="Unit_price_new"></label> <input type="text" name="Unit_price_new" id="Unit_price_new"></td> <td width="220"><label for="qty">Quantity:</label> <label for="quantity_new"></label> <input type="text" name="quantity_new" id="quantity_new"></td> </tr> <tr> <td><label for="express">Express Fee:</label> <label for="express_new"></label> <input type="text" name="express_new" id="express_new"></td> <td><label for="commission_new">Commission:</label> <input type="text" name="commission_new" id="commission_new"></td> <td><label for="customer_description">Description</label> <label for="description_new"></label> <textarea name="description_new" id="description_new" cols="45" rows="5"></textarea></td> </tr> <tr> <td> </td> <td colspan="2">Picture Upload: <input type="hidden" name="<?php echo ini_get("session.upload_progress.name");?>" value="123" /> <input name="file" type="file" autofocus="autofocus"/> <br /> </tr> <tr> <td colspan="3"><input type="reset" name="reset" id="reset" value="Reset"> <input type="submit" name="submit" id="submit" value="Submit The Product"></td> </tr> </table> </form> </div> <div class="neworder_listview"> <p> <form action="" method="post" name="list"> <input type="submit" name="del" id="del" value="Save"> <input type="submit" name="save" id="save" value="Del"> </p> <table width="1022" border="1" align="center"> <tr> <th width="24" scope="col"> </th> <th width="24" scope="col">Row#</th> <th width="137" scope="col">Manager</th> <th width="137" scope="col">Purchaser Desc</th> <th width="40" scope="col"><p>Link</p> <p>/Ссылки</p></th> <th width="53" scope="col">ФОТО</th> <th width="50" scope="col">Unit Price/Цена за еденицу товара</th> <th width="46" scope="col">Quantity/ Кол-во</th> <th width="138" scope="col">Total Unit Price/ Общая цена</th> <th width="89" scope="col">Express/Доставка по Китаю</th> <th width="119" scope="col">Description/Описание</th> <th width="89" scope="col">ADDITIONAL LINKS/ЗAMЕНЫ</th> </tr> <?php $username = "my username"; $password = "my pass"; $database = "userinfo"; $link = mysql_connect("localhost", "$username", "$password"); if(!$link) {echo("Failed to establish connection to mysql server"); exit();} $status = mysql_select_db($database); $query = "SELECT * FROM order_list"; $result = mysql_query($query); $num = mysql_num_rows($result); $i=0; while ($i < $num) { $field1_name=mysql_result($result,$i,"admin_st"); $field2_name=mysql_result($result,$i,"freelancer_st"); $field3_name=mysql_result($result,$i,"link"); $field4_name=mysql_result($result,$i,"picture"); $field5_name=mysql_result($result,$i,"unitprice"); $field6_name=mysql_result($result,$i,"qty"); $field7_name=mysql_result($result,$i,"express"); $field8_name=mysql_result($result,$i,"customer_st"); $i++; } ?> <?php $i=0; $row=1; while ($i < $num) { $f1=mysql_result($result,$i,"admin_st"); $f2=mysql_result($result,$i,"freelancer_st"); $f3=mysql_result($result,$i,"link"); $f4=mysql_result($result,$i,"pic_address"); $f5=mysql_result($result,$i,"unitprice"); $f6=mysql_result($result,$i,"qty"); $f7=mysql_result($result,$i,"express"); $f8=mysql_result($result,$i,"customer_st"); $totao_unit_price = $f5*$f6; ?> <tr> <td><input type="checkbox" name="del_chbox" id="del_chbox"> <td><p><font face="Arial"><input name="row_txtbox" type="text" id="row_txtbox" size="2" value="<?php echo $row; ?>"></font></td> <td><p><font face="Arial"> <textarea name="manager_txtbox" cols="10" id="manager_txtbox"><?php echo $f1; ?></textarea></font></td> <td><p><font face="Arial"> <textarea name="purchase_txtbox" cols="10" id="purchase_txtbox"><?php echo $f2; ?></textarea> </font></td> <td><font face="Arial"><a href="<?php $f3 ?>" target="_blank"><?php echo $f3; ?></a></font></td> <td><font face="Arial"><img src="<?php echo $f4;?>" width="100" align="middle"100></font></td> <td><font face="Arial"><input name="unitprice_txtbox" type="text" id="unitprice_txtbox" size="2" value="<?php echo $f5; ?>"></font></td> <td><font face="Arial"> <input name="qty_txtbox" type="text" id="qty_txtbox" size="2" value="<?php echo $f6; ?>"></font></td> <td><p><font face="Arial"><?php echo $totao_unit_price; ?></font></td> <td><p><font face="Arial"><input name="express2" type="text" id="express3" size="2" value="<?php echo $f7; ?>"></font></td> <td><p><font face="Arial"> <textarea name="custdesc_txtbox" cols="20" id="custdesc_txtbox"><?php echo $f8; ?></textarea></font></td> <td><input name="express2" type="text" id="express3" size="2" value="<?php echo "new link" ?>"></td> </tr> <p> <?php $i++; $row++; } ?> </table> </p> <p> </p> </form> Say I have two functions that convert from Dollar to Cents and Cents to Dollar. function convertToDollar($value) { $amount = $value / 100; return $amount; } function convertToCents($value) { $amount = $value * 100; return $amount; } Currently I convert all the Dollar amounts to cents and store the cents in the mysql database column. When I showcase those amounts on a page, I simply convert the Cents back to Dollar. Am I doing this correctly or is there a better way to store product pricing in mysql table? Hi there, I'm trying to get the full Product Name in the <title> of each of the product pages - I can't seem to figure out what to put in the product_info.php... I've tried a few different options but I'm not great with php Here's what I have currently but it creates errors... <script language="javascript"><!-- document.write('<title><?php echo TITLE; ?> : <?php echo $product_info['products_name']; ?> </title>'); //--></script> Hope someone can help - thanks so much! Hello everyone I have two dropdown lists. First one you can see the tables of my db and the second one the files inside a folder. The problem is that i can't send my selections from the dropdown list to an other file. My project is to choose a table, then a CSV file and then load the file in db. index.php: Code: [Select] <?php //EMFANISH PINAKWN include("../forma/dbCon.php"); echo "<form action='load_table_test.php' method='POST'>"; $sql="SHOW TABLES FROM misthodosia"; $result=mysql_query($sql); if (!$result) { echo "Υπάρχει πρόβλημα με την βάση\n"; echo 'MySQL Error: ' . mysql_error(); exit; } echo"<select>"; while ($row = mysql_fetch_row($result)) { echo "<option name='{row[0]}' value='{row[0]}'>{$row[0]}</option>"; } echo"</select>"; mysql_free_result($result); //==========================EMFANISH ARXEIWN========================== function populateDropdown(){ $path = glob("C:\\xampp\\htdocs\\dbadmin\\upload_files\\*"); //the double \\ is not a typo you //have to escape it //if the path cannot be found if(!($path)){ echo("Δεν υπάρχει ο φάκελος"); return; }//if //the path is valid else{ foreach($path as $k){ $i = basename($k); echo "<option name='$i'>".$i."</option>"; }//foreach }//else }//populateDropdown echo"<select>"; populateDropdown(); echo"</select> "; echo"<input type='submit' name='submit' value='Φόρτωσε1111111' />"; echo "</form>"; $hello="hello"; ?> load_table_test.php: Code: [Select] <?php include("../forma/dbCon.php"); echo $_POST['hello']; echo $_POST['{row[0]}']; echo $i; //$pinakas=$_POST['pinakas'] //$arxeio=$_POST['arxeio'] //$pinakas=$_POST['row'] //$arxeio=$_POST['diadromi'] //mysql_query("LOAD DATA LOCAL INFILE "$arxeio" INTO TABLE $pinakas //FIELDS //TERMINATED BY ',' //ENCLOSED BY '\"' //LINES TERMINATED BY '\n') echo "$arxeio"; echo "$pinakas"; echo "<br/><br/><br/><br/><br/><a href='index.php'>Επιστροφή στην προηγούμενη σελίδα.</a>"; ?> errors: Code: [Select] Notice: Undefined index: hello in C:\xampp\htdocs\dbadmin\load_table_test.php on line 6 Notice: Undefined index: {row[0]} in C:\xampp\htdocs\dbadmin\load_table_test.php on line 8 Notice: Undefined variable: i in C:\xampp\htdocs\dbadmin\load_table_test.php on line 9 Notice: Undefined variable: arxeio in C:\xampp\htdocs\dbadmin\load_table_test.php on line 27 Notice: Undefined variable: pinakas in C:\xampp\htdocs\dbadmin\load_table_test.php on line 28 yeah im back again with yet another thing i need some help lol. what im trying to do is set up a "Feature" box that will pull data from multiple tables by date. as of right now i would like to pull data from my "news" table and my "event" table. both need to be displayed differently. table contents: News ------- id date header news edate Event ------- id eventdate cdate header description image location so now I would like to make the mysql_query to get the info from both tables and list them by recent date. "date" and "cdate" are the dates i want the query to read from and of course display from most recent. Ok, so I've spent quite a bit of time piecing together this solution from a variety of sources. As such, I may have something in my code below that doesn't make sense or isn't neccessary. Please let me know if that is the case. I'm creating an administrative form that users will you to add/remove items from a MySQL table that lists open positions for a facility. The foreach loop generates all of the possible job specialties from a table called 'specialty_list'. This table is joined to a second table ('open_positions') that lists any positions that have been selected previously. Where I'm stuck is getting the checkbox to be checked if the facility_ID from the open_positions table matches the $id passed in the URL via ?facility_id=''. Here's where I am so far: $query = "SELECT specialty_list.specialty_displayname , specialty_shortname , open_positions.position , facility_ID FROM specialty_list LEFT OUTER JOIN open_positions ON open_positions.position = specialty_list.specialty_shortname ORDER BY specialty_list.specialty_shortname"; $results = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($results)) { $positions[$row['specialty_shortname']] = $row['specialty_displayname']; } echo "<form method='POST' action='checkbox.php'>"; foreach($positions as $specialty_shortname => $specialty_displayname) { $facility_ID = $row['facility_ID']; $checked = $facility_ID == $row['facility_ID'] ? ' checked' : ''; echo "<input type='checkbox' name='position[]' value=\"{$specialty_shortname}\"{$checked}> {$specialty_displayname}</input><br/>"; } echo "<input type='hidden' name='facility_ID' value='$id'>"; echo "<input type='submit' value='Submit Checkboxes!'>"; echo "</form>"; Any ideas how to get this working? I feel like I'm very close, but I just can't get it. I also tried starting from scratch with a WHILE statement instead of a FOREACH, but haven't tweaked it enough to prevent duplicate checkboxes. With that in mind, here it is, just in case that's a better direction: $query = "SELECT specialty_list.specialty_displayname , specialty_shortname , open_positions.position , facility_ID FROM specialty_list LEFT OUTER JOIN open_positions ON open_positions.position = specialty_list.specialty_shortname ORDER BY specialty_list.specialty_shortname"; $results = mysql_query($query) or die(mysql_error()); echo "<form method='POST' action='checkbox.php'>"; while($row=mysql_fetch_assoc($results)) { $facility_ID = $row['facility_ID']; $specialty_shortname = $row['specialty_shortname']; $specialty_displayname = $row['specialty_displayname']; if ($facililty_ID==$id) { $checked=' checked'; } echo "<input type='checkbox' name='position[]' value=\"$specialty_shortname\"$checked> $specialty_displayname</input><br/>"; } echo "<input type='hidden' name='facility_ID' value='$id'>"; echo "<input type='submit' value='Submit Checkboxes!'>"; echo "</form>"; Hi, I am re-visiting my database table relationship for criminal incidents. Six tables are involved plus a junction table to make it seven tables in total. I need someone to review this relationship and advise whether or not it is correctly set up. The relationships are as follows: 1. A person can belong to more than one incident: t_persons (one-to-many) t)_incidents_persons 2. A person can only have one nationality by birth t_persons (one-to-one) t_countries 3. An agency can have more than one incident t_agencies (one-to-many) t_incidents 4. A status (e.g. closed incident) can belong to more than one incident t_status (one-to-many_ t_incidents 5. A keyword (i.e. offence type eg theft) t_offencekeywords (one-to-many) t_incidents How we can make the connection to ODBC in PHP If any shares the coding part then it would be great. (Table to database) I have two tables. Let's call the first one items and the second one item categories. Now the items table would look something like this: id(auto_increment id) name description categoryid The item categories table would look something like this: categoryid name description An entry in the items table would look something like this: categoryid = 1,2 name = Thing description = something id = 1 Say I want to retrieve records that contain "1" in the categoryid column. How would I do that? Hi can anybody help I need to export and download tables from a database into a excel sheet. I have this code and it works what I need is to export specific fields and not just the whole table can anyone help modifying the code to export certain fields within the table please? Here is the code... Code: [Select] <?php $host = 'localhost'; $user = 'user'; $pass = 'password'; $db = 'qdbname'; $table = 'tablename'; $file = 'export'; $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error()); mysql_select_db($db) or die("Can not connect."); $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field']."; "; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j]."; "; } $csv_output .= "\n"; } $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?> Hi guys, Is it possible to insert into two tables in a database? Thanks Hi everyone. I would like to do this: In page1.php, I need to make a few checkboxes, which when the user clicks "next" button, transfers the data (which checkboxes were clicked) to a database table. Then, when the user clicks a button "next", he is moved to another page, page2.php, from which he is automatically transferred to page3.php. At page3.php those values are gathered from the database, and the user has to click "next" button again, then those values are written into another table, in the same or another database. How can I do this? I've not much knowledge with neither SQL, neither PHP. I hope you will help me make this work, I'm making a little system for my HTML website. Thanks, if you do! This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=353621.0 Hey All, Been banging my head into the wall on this one. I have 2 tables one for users 'myMembers' and one for products 'products'. Each table has a auto increment id. The myMembers id is the user id and the products table id is for the product id. I have a row in the products table for agent_id. I would like the agent_id to be filled with the id from the myMembers table. I took a look at the manual; still do not understand how to take the id from the myMembers table then place that id into the agent_id; so the products(id) can be listed under the specific members id(agent_id) in the products table. So far my script for the products table inserts items correctly, but does not file under the specific agent_id. Here is the script for entering items to the products table. Thanks for the guidance! <?php // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Delete Item Question to Admin, and Delete Product if they choose if (isset($_GET['deleteid'])) { echo 'Do you really want to delete product with ID of ' . $_GET['deleteid'] . '? <a href="inventory_list.php?yesdelete=' . $_GET['deleteid'] . '">Yes</a> | <a href="inventory_list.php">No</a>'; exit(); } if (isset($_GET['yesdelete'])) { // remove item from system and delete its picture // delete from database $id_to_delete = $_GET['yesdelete']; $sql = mysql_query("DELETE FROM products WHERE id='$id_to_delete' LIMIT 1") or die (mysql_error()); // unlink the image from server // Remove The Pic ------------------------------------------- $pictodelete = ("../inventory_images/$id_to_delete.jpg"); if (file_exists($pictodelete)) { unlink($pictodelete); } header("location: inventory_list.php"); exit(); } ?> <?php // Parse the form data and add inventory item to the system if (isset($_POST['product_name'])) { $product_name = mysql_real_escape_string($_POST['product_name']); $price = mysql_real_escape_string($_POST['price']); $category = mysql_real_escape_string($_POST['category']); $subcategory = mysql_real_escape_string($_POST['subcategory']); $details = mysql_real_escape_string($_POST['details']); // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1"); $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0) { echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>'; exit(); } // Add this product into the database now $sql = mysql_query("INSERT INTO products (product_name, agent_id price, details, category, subcategory, date_added) VALUES('$product_name','$price','$details','$category','$subcategory',now())") or die (mysql_error()); $pid = mysql_insert_id(); // Place image in the folder $newname = "$pid.jpg"; move_uploaded_file( $_FILES['fileField']['tmp_name'], "../inventory_images/$newname"); header("location: inventory_list.php"); exit(); } ?> <?php // This block grabs the whole list for viewing $product_list = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $product_list .= "Product ID: $id - <strong>$product_name</strong> - $$price - <em>Added $date_added</em> <a href='inventory_edit.php?pid=$id'>edit</a> • <a href='inventory_list.php?deleteid=$id'>delete</a><br />"; } } else { $product_list = "You have no products yet"; } ?> |