Jump to content

Inventory_list.php


CASHOUT

Recommended Posts

PLEASE help if you CAN. It will be greatly appreciated

when i try and add an inventory item to the inventory_list.php, i receive this message:

 

Unknown column 'category' in 'field list'

 

 

 

<?php 
session_start();
if (!isset($_SESSION["manager"])) {
    header("location: admin_login.php"); 
    exit();
}
// Be sure to check that this manager SESSION value is in fact in the database
$managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters
$manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters
// Run mySQL query to be sure that this person is an admin and that their password session var equals the database information
// Connect to the MySQL database  
include "../storescripts/connect_to_mysql.php"; 
$sql = mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); // query the person
// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount == 0) { // evaluate the count
 echo "Your login session data is not on record in the database.";
     exit();
}
?>
<?php 
// Error Reporting
error_reporting(E_ALL);
ini_set('display_errors','1');
?>
<?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 the 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 herf="inventory_list.php">click here</a>';
	exit();
}
// Add this product into the database now
$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();
// Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$newname");
}
?>
<?php
// This block grabs the whole list for viewing
$product_list = "";
$sql = mysql_query("SELECT * FROM products");
$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"];
	$product_list .= "$id - $product_name<br />";
}
} else {
$product_list = "You have no products listed in your 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.php");?>
  <div id="pageContent"><br />
    <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>
    <a name="inventoryForm" id="inventoryForm"></a>
    <h3>
      Add New Inventory Item Form<br />
    </h3>
    <form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post">
    <table width="90%" border="0" cellpadding="6" cellspacing="0">
      <tr>
        <td width="20%" align="right">Product Name</td>
        <td width="80%"><label>
        <input name="product_name" type="text" id="product_name" size="64" />
        </label>
      </tr>
      <tr>
        <td align="right">Product Price</td>
        <td><label>
        $
        <input name="price" type="text" id="price" size="12" />
        </label>
      </tr>
      <tr>
        <td align="right">Category</td>
        <td><label>
        <select name="category" id="category">
        <option value=""></option>
        <option value="Gold">Gold</option>
        <option value="Silver">Silver</option>
        <option value="Platinum">Platinum</option>
        </select>
        </label></td>
      </tr>
      <tr>
        <td align="right">Subcategory</td>
        <td><select name="subcategory" id"subcategory">
        <option value="Bracelets">Bracelets</option>
        <option value="Earings">Earings</option>
        <option value="Estate">Estate</option>
        <option value="Necklace">Necklace</option>
        <option value="Pendents">Pendents</option>
        <option value="Rings">Rings</option>
        <option value="Watches">Watches</option>
        </select></td>
      </tr>
      <tr>
        <td align="right">Product Details</td>
        <td><label>
        <textarea name="details" type="details" cols="64" rows="5"></textarea>
        </label></td>
      </tr>
      <tr>
        <td align="right">Product Images</td>
        <td><label>
        <input type="file" name="fileField" value="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>
   <br />
    <br />
  </div>
  <?php include_once("../template_footer.php");?>
</div>
</body>
</html>

Link to comment
Share on other sites

Looks fine to me, but I did notice that $category appears as the fourth field in your SQL statement, but when you are escaping the data, it appears as the third item.  Try moving $details in front of $category when you are escaping your data so it's in the same position in your SQL statement.  I've seen weirder things.

Link to comment
Share on other sites

i don't think you can insert the date like that:

$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());

try this:http://www.ntchosting.com/mysql/insert-date.html

 

It is possible.  I use now() all the time.

Link to comment
Share on other sites

Looks fine to me, but I did notice that $category appears as the fourth field in your SQL statement, but when you are escaping the data, it appears as the third item.  Try moving $details in front of $category when you are escaping your data so it's in the same position in your SQL statement.  I've seen weirder things.

 

I tried moving $details in front of $category and got the same result, any other ideas??

 

Is this what you meant?

 

<?php 
session_start();
if (!isset($_SESSION["manager"])) {
    header("location: admin_login.php"); 
    exit();
}
// Be sure to check that this manager SESSION value is in fact in the database
$managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters
$manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters
// Run mySQL query to be sure that this person is an admin and that their password session var equals the database information
// Connect to the MySQL database  
include "../storescripts/connect_to_mysql.php"; 
$sql = mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); // query the person
// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount == 0) { // evaluate the count
 echo "Your login session data is not on record in the database.";
     exit();
}
?>
<?php 
// Error Reporting
error_reporting(E_ALL);
ini_set('display_errors','1');
?>
<?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 the 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 herf="inventory_list.php">click here</a>';
	exit();
}
// Add this product into the database now
$sql = mysql_query("INSERT INTO products (product_name, price, category, subcategory, details, date_added)
	VALUES('$product_name','$price','$category','$subcategory','$details',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");
}
?>
<?php
// This block grabs the whole list for viewing
$product_list = "";
$sql = mysql_query("SELECT * FROM products");
$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"];
	$product_list .= "$id - $product_name<br />";
}
} else {
$product_list = "You have no products listed in your 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.php");?>
  <div id="pageContent"><br />
    <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>
    <a name="inventoryForm" id="inventoryForm"></a>
    <h3>
      Add New Inventory Item Form<br />
    </h3>
    <form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post">
    <table width="90%" border="0" cellpadding="6" cellspacing="0">
      <tr>
        <td width="20%" align="right">Product Name</td>
        <td width="80%"><label>
        <input name="product_name" type="text" id="product_name" size="64" />
        </label>
      </tr>
      <tr>
        <td align="right">Product Price</td>
        <td><label>
        $
        <input name="price" type="text" id="price" size="12" />
        </label>
      </tr>
      <tr>
        <td align="right">Category</td>
        <td><label>
        <select name="category" id="category">
        <option value=""></option>
        <option value="Gold">Gold</option>
        <option value="Silver">Silver</option>
        <option value="Platinum">Platinum</option>
        </select>
        </label></td>
      </tr>
      <tr>
        <td align="right">Subcategory</td>
        <td><select name="subcategory" id"subcategory">
        <option value="Bracelets">Bracelets</option>
        <option value="Earings">Earings</option>
        <option value="Estate">Estate</option>
        <option value="Necklace">Necklace</option>
        <option value="Pendents">Pendents</option>
        <option value="Rings">Rings</option>
        <option value="Watches">Watches</option>
        </select></td>
      </tr>
      <tr>
        <td align="right">Product Details</td>
        <td><label>
        <textarea name="details" type="details" cols="64" rows="5"></textarea>
        </label></td>
      </tr>
      <tr>
        <td align="right">Product Images</td>
        <td><label>
        <input type="file" name="fileField" value="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>
   <br />
    <br />
  </div>
  <?php include_once("../template_footer.php");?>
</div>
</body>
</html>

Link to comment
Share on other sites

I tried moving $details in front of $category and got the same result, any other ideas??

it doesn't matter what order of data you grabing from the form as long as you match them up correctly.

and try to swap the position of the category like u did in the insert statement but in the database...

Link to comment
Share on other sites

i checked my products table and sure enough there was a spelling error on the category column. I fixed the the spelling error, but still got the same error. I'm not sure if there are other problems in the products table script, so i will post it also

 

 

create_products_table.php

 

<?php   
// Connect to the MySQL database   
require"connect_to_mysql.php";  

$sqlCommand="CREATE TABLE products(
	id int(11)NOT NULL auto_increment,
	product_name varchar(255)NOT NULL,
	price varchar(16)NOT NULL,
	category varchar(64)NOT NULL,
	subcategory varchar(64)NOT NULL,
	details text NOT NULL,
	date_added date NOT NULL,
	PRIMARY KEY (id),
	UNIQUE KEY product_name(product_name)
	)";
if(mysql_query($sqlCommand)){
echo"Your products table has been created successfully!";
}else{
echo"CRITICAL ERROR:products table has not been created.";
}
?>

 

 

 

inventory_list.php

 

<?php 
session_start();
if (!isset($_SESSION["manager"])) {
    header("location: admin_login.php"); 
    exit();
}
// Be sure to check that this manager SESSION value is in fact in the database
$managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters
$manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters
// Run mySQL query to be sure that this person is an admin and that their password session var equals the database information
// Connect to the MySQL database  
include "../storescripts/connect_to_mysql.php"; 
$sql = mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); // query the person
// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount == 0) { // evaluate the count
 echo "Your login session data is not on record in the database.";
     exit();
}
?>
<?php 
// Error Reporting
error_reporting(E_ALL);
ini_set('display_errors','1');
?>
<?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 the 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 herf="inventory_list.php">click here</a>';
	exit();
}
// Add this product into the database now
$sql = mysql_query("INSERT INTO products (product_name, price, category, subcategory, details, date_added)
	VALUES('$product_name','$price','$category','$subcategory','$details',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");
}
?>
<?php
// This block grabs the whole list for viewing
$product_list = "";
$sql = mysql_query("SELECT * FROM products");
$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"];
	$product_list .= "$id - $product_name<br />";
}
} else {
$product_list = "You have no products listed in your 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.php");?>
  <div id="pageContent"><br />
    <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>
    <a name="inventoryForm" id="inventoryForm"></a>
    <h3>
      Add New Inventory Item Form<br />
    </h3>
    <form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post">
    <table width="90%" border="0" cellpadding="6" cellspacing="0">
      <tr>
        <td width="20%" align="right">Product Name</td>
        <td width="80%"><label>
        <input name="product_name" type="text" id="product_name" size="64" />
        </label>
      </tr>
      <tr>
        <td align="right">Product Price</td>
        <td><label>
        $
        <input name="price" type="text" id="price" size="12" />
        </label>
      </tr>
      <tr>
        <td align="right">Category</td>
        <td><label>
        <select name="category" id="category">
        <option value=""></option>
        <option value="Gold">Gold</option>
        <option value="Silver">Silver</option>
        <option value="Platinum">Platinum</option>
        </select>
        </label></td>
      </tr>
      <tr>
        <td align="right">Subcategory</td>
        <td><select name="subcategory" id"subcategory">
        <option value="Bracelets">Bracelets</option>
        <option value="Earings">Earings</option>
        <option value="Estate">Estate</option>
        <option value="Necklace">Necklace</option>
        <option value="Pendents">Pendents</option>
        <option value="Rings">Rings</option>
        <option value="Watches">Watches</option>
        </select></td>
      </tr>
      <tr>
        <td align="right">Product Details</td>
        <td><label>
        <textarea name="details" type="details" cols="64" rows="5"></textarea>
        </label></td>
      </tr>
      <tr>
        <td align="right">Product Images</td>
        <td><label>
        <input type="file" name="fileField" value="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>
   <br />
    <br />
  </div>
  <?php include_once("../template_footer.php");?>
</div>
</body>
</html>

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.