shebbycs Posted June 6, 2012 Share Posted June 6, 2012 inventory_list.php <?php session_start(); if(empty($_SESSION['is_logged_in'])) { header("location:index.php"); exit(); } ?> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php mysql_connect("localhost","root") or die ("could not connect to mysql"); mysql_select_db("pensotech_mystore") or die ("no database"); 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>'; } if(isset($_GET['yesdelete'])) { $id_to_delete=$_GET['yesdelete']; $sql=mysql_query("DELETE FROM products WHERE id='$id_to_delete' LIMIT 1") or die (mysql_error()); $pictodelete = ("../inventory_images/$id_to_delete.jpg"); if(file_exists($pictodelete)) { unlink($pictodelete); } header("location:inventory_list.php"); exit(); } ?> <?php 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']); $sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1 "); $productmatch = mysql_num_rows($sql); if($productmatch > 0) { echo 'Sorry the product you want to insert is going to be duplicate, <a href="inventory_list.php">click here</a>'; exit(); } $sql = mysql_query("INSERT INTO products (product_name,price,details,category,subcategory,date_added) VALUES('$product_name','$price','$details','$category','$subcategory',now())") or die (mysql_error()); $pid=mysql_insert_id(); $newname="$pid.jpg"; move_uploaded_file($_FILES['fileField']['tmp_name'],"../inventory_images/$newname"); header("location:inventory_list.php"); exit(); } ?> <?php $product_list=""; $sql=mysql_query("SELECT*FROM products ORDER BY date_added DESC"); $product_count=mysql_num_rows($sql); if($product_count>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="No products have been added in the store yet"; } ?> <!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>Inventory List</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_admin.php");?> <div id="pageContent"> <p> </p> <div align="right" style="margin-right:32px;"><a href="inventory_list.php#inventoryForm">+ Add New Inventory Item</a></div> <div align="left" style="margin-left:24px;"> <h2>Inventory list</h2> <?php echo $product_list; ?> </div><hr /> <a name="inventoryForm" id="inventoryForm"></a> <h3>↓Add New Inventory Item Form ↓</h3> <form action="inventory_list.php" enctype="multipart/form-data" name="borang" id="borang" method="post"> <table width="579" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="25%">Product Name</td> <td width="75%"><label><input name="product_name" type="text" id="product_name" size="64"/></label></td> </tr> <tr> <td>Product Price</td> <td><label>RM<input name="price" type="text" id="price" size="12" /></label></td> </tr> <tr> <td align="right">Category</td> <td><label> <select name="category" id="category"> <option value=""></option> <option value="Desktop PC">Desktop PC</option> <option value="Notebook">Notebook</option></select></label></td> </tr> <tr> <td align="right">Subcategory</td> <td><select name="subcategory" id="subcategory"> <option value=""></option> <option value="Processor">Processor</option> <option value="MB">Motherboard</option> <option value="HDD">Hard Disk</option> <option value="RAM">Memory</option> <option value="GC">Graphic Card</option></select></td> </tr> <tr> <td>Product Details</td> <td><label><textarea name="details" id="details" cols="64" rows="5"></textarea></label></td> </tr> <tr> <td>Product Image</td> <td><label><input type="file" name="fileField" id="fileField"/></label></td> </tr> <tr> <td> </td> <td><label><input type="submit" name="button" id="button" value="Add This Item Now"/></label></td> </tr> </table> </form> <p> </p> </div> <?php include_once("../template_footer.php");?> </div> </body> </html> inventory_edit.php <?php session_start(); if(empty($_SESSION['is_logged_in'])) { header("location:index.php"); exit(); } ?> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php mysql_connect("localhost","root") or die ("could not connect to mysql"); mysql_select_db("pensotech_mystore") or die ("no database"); if(isset($_POST['product_name'])) { $pid = mysql_real_escape_string($_POST['thisID']); $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']); $sql = mysql_query("UPDATE products SET product_name='$product_name', price='$price',details='$details', category='$category', subcategory='$subcategory' WHERE id='$pid' "); if($_FILES['fileField']['tmp_name']!="") { $newname="$pid.jpg"; move_uploaded_file($_FILES['fileField']['tmp_name'],"../inventory_images/$newname"); } header("location:inventory_list.php"); exit(); } ?> <?php if(isset($_GET['pid'])) { $targetID=$_GET['pid']; $sql=mysql_query("SELECT * FROM products WHERE id='$targetID' LIMIT 1"); $productCount=mysql_num_rows($sql); if($productCount > 0) { while($row=mysql_fetch_array($sql)) { $id=$row["id"]; $product_name=$row["product_name"]; $price=$row["price"]; $category=$row["category"]; $subcategory=$row["subcategory"]; $details=$row["details"]; $date_added = strftime("%b %d,%Y",strtotime($row["date_added"])); } } else { echo 'Sorry the product is not exist'; exit(); } } $product_list=""; $sql=mysql_query("SELECT*FROM products ORDER BY date_added DESC"); $product_count=mysql_num_rows($sql); if($product_count>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="No products have been added in the store yet"; } ?> <!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>Inventory List</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_admin.php");?> <div id="pageContent"> <p> </p> <div align="right" style="margin-right:32px;"><a href="inventory_list.php#inventoryForm">+ Add New Inventory Item</a></div> <div align="left" style="margin-left:24px;"> <h2>Inventory list</h2> <?php echo $product_list; ?> </div><hr /> <a name="inventoryForm" id="inventoryForm"></a> <h3>↓Add New Inventory Item Form ↓</h3> <form action="inventory_edit.php" enctype="multipart/form-data" name="borang" id="borang" method="post"> <table width="579" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="25%">Product Name</td> <td width="75%"><label><input name="product_name" type="text" id="product_name" size="64" value="<?php echo $product_name; ?>"/></label></td> </tr> <tr> <td>Product Price</td> <td><label>RM<input name="price" type="text" id="price" size="12" value="<?php echo $price; ?>" /></label></td> </tr> <tr> <td align="right">Category</td> <td><label> <select name="category" id="category"> <option value="<?php echo $category; ?>"><?php echo $category; ?></option> <option value="Desktop PC">Desktop PC</option> <option value="Notebook">Notebook</option></select></label></td> </tr> <tr> <td align="right">Subcategory</td> <td><select name="subcategory" id="subcategory"> <option value="<?php echo $subcategory; ?>"><?php echo $subcategory; ?></option> <option value="Processor">Processor</option> <option value="MB">Motherboard</option> <option value="HDD">Hard Disk</option> <option value="RAM">Memory</option> <option value="GC">Graphic Card</option></select></td> </tr> <tr> <td>Product Details</td> <td><label><textarea name="details" id="details" cols="64" rows="5" ><?php echo $details; ?></textarea></label></td> </tr> <tr> <td>Product Image</td> <td><label><input type="file" name="fileField" id="fileField"/></label></td> </tr> <tr> <td> </td> <td><label> <input name="thisID" type="hidden" value="<?php echo $targetID; ?>" /> <input type="submit" name="button" id="button" value="Make Changes"/></label></td> </tr> </table> </form> <p> </p> </div> <?php include_once("../template_footer.php");?> </div> </body> </html> here the screenshots Quote Link to comment Share on other sites More sharing options...
shebbycs Posted June 6, 2012 Author Share Posted June 6, 2012 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Pensotech Cart System\storeadmin\inventory_list.php:10) in C:\xampp\htdocs\Pensotech Cart System\storeadmin\inventory_list.php on line 54 i got this error if want to put another new inventory list item Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 6, 2012 Share Posted June 6, 2012 http://www.phpfreaks.com/forums/index.php?topic=37442.0 Quote Link to comment Share on other sites More sharing options...
shebbycs Posted June 7, 2012 Author Share Posted June 7, 2012 b4 that im can post without header warning error may i knw which part is error and also that product name and product price not showing Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.