Jump to content
Killersites Forums

too many lines of code i can see triple


zeusthegreat
 Share

Recommended Posts

inventory.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 everyhting 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 varequals 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

header("location: ../index.php");

exit();

}

?>

<?php

//Error reporting show errors in your scripts

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 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, price, details, category, subcategory, date_added)

VALUES('$product_name','$price','$details','$category','$subcategory',now())") or die (mysql_error()); //now adds todays date to whatever you are doing

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

$productCount = mysql_num_rows($sql); //count the output ammount

if ($productCount > 0){

while($row =mysql_fetch_array($sql)){//loops will interate over an array of data

$id = $row["id"];

$product_name = $row["product_name"];

$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 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"></div>

<div align="center" id="mainWrapper">

 

 

 

<?php include_once("../template_header.php"); ?>

 

<?php include_once("../template_sidebar.php"); ?>

 

 

 

 

 

<div align="left" 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>

<hr />

<a name="inventoryForm" id="inventoryForm"></a>

<h3 align="center">

↓ Add New Inventory Item Form ↓

<a name="inventoryForm" id="inventoryForm"></a>

</h3>

<form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myform" method="post">

<table width="90%" border="0" cellspacing="0" cellpadding="6">

<tr>

<td width="20%" align="right">Product Name</td>

<td width="80%"><label>

black hat

</label></td>

</tr>

<tr>

<td align="right">Product Price</td>

<td><label>

£

20

</label></td>

</tr>

<tr>

<td align="right">Category</td>

<td><label>

<select name="category" id="category">

<option value="Clothing">Clothing</option>

<option value="Electronics">Electronics</option>

</select>

</label></td>

</tr>

<tr>

<td align="right">Subcategory</td>

<td><select name="subcategory" id="subcategory">

<option value=""></option>

<option value="Hats">Hats</option>

<option value="Pants">Pants</option>

<option value="Shirts">Shirts</option>

</select></td>

</tr>

<tr>

<td align="right">Product Details</td>

<td><label>

<textarea name="details" id="details" cols="64" rows="5"></textarea>

</label></td>

</tr>

<tr>

<td align="right">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>

</div>

<?php include_once("../template_footer.php"); ?>

 

</div>

</body>

</html>

 

 

 

have loaded in an item just to see if it works and after imputting in all the fields and submitting this error shows

 

 

 

 

 

! ) Notice: Undefined variable: price in C:\wamp\www\myNewweb\storeadmin\inventory_list.php on line 64

Call Stack

# Time Memory Function Location

1 0.0024 397104 {main}( ) ..\inventory_list.php:0

 

( ! ) Notice: Undefined variable: date_added in C:\wamp\www\myNewweb\storeadmin\inventory_list.php on line 64

Call Stack

# Time Memory Function Location

1 0.0024 397104 {main}( ) ..\inventory_list.php:0

 

 

I have no idea does it mean that it does not recognize the price

 

the date added i thought this came from a server anyway!

 

am i on the right track!

Edited by talos
Link to comment
Share on other sites

When you say you get a "woops page", what sort of page is that? A page that your browser shows when it can't find the correct file (basically, a 404 page) or is it finding the page fine, but you are getting PHP errors?

 

If it's just a 404 error, you need to check your paths and make sure the path to the file is correct and the file itself is spelled correctly. Uppercase and lowercase count: inventory_Edit.php is different than inventory_edit.php. According to your code snippet in your last post, your inventory_edit.php file should be in the same folder as whatever file that code comes from.

Link to comment
Share on other sites

I looked at your code, I had to clean it up a little in notepad++ to read it though.

 

 

The problem is you are accessing variables that aren't created. If you look here:

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, price, details, category, subcategory, date_added)
VALUES('$product_name','$price','$details','$category','$subcategory',now())") or die (mysql_error()); //now adds todays date to whatever you are doing
$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();
}

 

That is the only place you set $price, and you don't even define $date_added anywhere. And that spot redirects to inventory_list.php

 

Now look at this:

//This block grabs the whole list for viewing
$product_list = "";
$sql = mysql_query("SELECT * FROM products");
$productCount = mysql_num_rows($sql); //count the output ammount
if ($productCount > 0) {
while($row =mysql_fetch_array($sql)) {//loops will interate over an array of data
	$id = $row["id"];
	$product_name = $row["product_name"];
	$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 listed in your store yet";
}

 

In here you do a mysql_fetch_array putting the result in $row. What you need to do is make the two variables in that while loop, just like you did $product_name and $id.

 

Like so, assuming I am correctly looking at how your database and all that are layed out.

while($row =mysql_fetch_array($sql)) {//loops will interate over an array of data
$id = $row["id"];
$product_name = $row["product_name"];
$date_added = $row["date_added"];
$price = $row["price"];
$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 />";
}

 

Like Ben said, the error you were experiencing was due to a variable being called that didn't exist. You can't attempt to get the value of something that doesn't exist. If you note the one place you do set price is around line 32 I believe, and that looks to just be when you add the item. At the end of that if block of code it hits a header() which redirects the browser in tern destroying all of those variables you set in that if block.

 

 

As far as I can tell, that is the problem you mentioned anyway.

Link to comment
Share on other sites

well everything was going sweet until i typed

 

$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));

 

 

then it returned below

( ! ) Notice: Undefined variable: date_added in C:\wamp\www\myNewweb\storeadmin\inventory_list.php on line 61

Call Stack

# Time Memory Function Location

1 0.0023 399928 {main}( ) ..\inventory_list.php:0

 

 

what code do i have to put on what line as basically all was going fine until i typed the above on line 61

<?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 everyhting 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 varequals 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

header("location: ../index.php");

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 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 ammount

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, Price, details, category, subcategory, date_added) VALUES('$product_name','$price','$details','$category','$subcategory',now())") or die (mysql_error()); //now adds todays date

$id = 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 the output ammount

if ($productCount > 0){

while($row = mysql_fetch_array($sql)){

$id = $row["id"];

$product_name = $row["product_name"];

$date_added = strftime("%b %d, %Y", strtotime($date_added));

$product_list .= "$id-$product_name    <a href='#'>edit</a> •<a href='#'>  delete</a><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" />

<style type="text/css">

body {

background-color: #FFF;

}

</style>

</head>

 

<body>

<div align="center"></div>

<div align="center" id="mainWrapper">

 

 

 

<?php include_once("../template_header.php"); ?>

 

<?php include_once("../template_sidebar.php"); ?>

 

 

 

 

 

<div align="left" id="pageContent">

<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 />

 

<div>

<a name="inventoryForm" id="inventoryForm"></a>

<h3 align="center">

↓ Add New Inventory Item Form ↓

</h3>

</div>

<form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myform" method="post">

<table width="90%" border="0" cellspacing="0" cellpadding="6">

<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></td>

</tr>

<tr>

<td align="right">Product Price</td>

<td><label>

£ <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="Clothing">Clothing</option>

</select>

</label></td>

</tr>

<tr>

<td align="right">Subcategory</td>

<td><select name="subcategory" id="subcategory">

<option value=""></option>

<option value="Hats">Hats</option>

<option value="Pants">Pants</option>

<option value="Shirts">Shirts</option>

</select></td>

</tr>

<tr>

<td align="right">Product Details</td>

<td><label>

<textarea name="details" id="details" cols="64" rows="5"></textarea>

</label></td>

</tr>

<tr>

<td align="right">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>

 

 

 

<br/>

<br/>

</div>

<?php include_once("../template_footer.php"); ?>

 

 

</div>

</body>

</html>

 

 

i am struggling to know what to type and where and as for the $price i thought i had done that also.

 

where have i failed with price

 

 

i have tryed this but still an error

 

?php

//This block grabs the whole list for viewing

$product_list = "";

$sql = mysql_query("SELECT * FROM products");

$productCount = mysql_num_rows($sql);//count the the output ammount

if ($productCount > 0){

while($row = mysql_fetch_array($sql)){

$id = $row["id"];

$price = $row["price"];

$product_name = $row["product_name"];

$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));

$product_list .= "$id-$product_name    <a href='#'>edit</a> •<a href='#'>  delete</a><br/>";

}

 

}else{

$product_list = "You have no products listed in your store Yet";

}

?>

 

( ! ) Notice: Undefined index: date_added in C:\wamp\www\myNewweb\storeadmin\inventory_list.php on line 62

Call Stack

# Time Memory Function Location

1 0.0026 400360 {main}( ) ..\inventory_list.php:0

Link to comment
Share on other sites

$product_list .= "$id-$product_name - $price - $date_added    <a href='#'>edit</a> •<a href='#'>  delete</a><br/>";

 

 

( ! ) Notice: Undefined index: date_added in C:\wamp\www\myNewweb\storeadmin\inventory_list.php on line 62

Call Stack

# Time Memory Function Location

1 0.0008 401312 {main}( ) ..\inventory_list.php:0

 

 

Home Web Design Web Development E Commerce Pricing

Web Design

Graphic Design

Pay Monthly

 

Pricing

Template

Contact

+Add New Inventory Item

Inventory List

9-hat - 10 - Jan 01, 1970 edit • delete

 

but there is still an error

 

am i going of track.

 

 

it returns the date (the date is wrong though)

 

--------------------------------------------------------------------------------

Edited by talos
Link to comment
Share on other sites

Maybe you should var_dump the $row variable:

 

while($row = mysql_fetch_array($sql)){
echo '<pre>';
var_dump($row);
echo '</pre>';
}

 

Because if you are doing

$price = $row["price"];

 

Then the variable $price should at least exist.

 

Also, please put your code in the code tags. Look here for a reference on them: http://www.killersites.com/community/index.php?app=forums&module=extras&section=legends&do=bbcode (Scroll down until you see the bold and green "Code" section. It should be near the top).

 

It would make it a heck of a lot easier to read.

  • Upvote 1
Link to comment
Share on other sites

I have sorted the price showing but the below is an error for the date_added

 

 

 

( ! ) Notice: Undefined index: date_added in C:\wamp\www\myNewweb\storeadmin\inventory_list.php on line 63

 

this is what error the browser returns

 

Call Stack

# Time Memory Function Location

1 0.0026 400776 {main}( ) ..\inventory_list.php:0

 

 

the date returns but it is wrong

Link to comment
Share on other sites

ia m unsure how to or where to with this code

 

while($row = mysql_fetch_array($sql)){

echo '<pre>';

var_dump($row);

echo '</pre>';

}

 

 

//This block grabs the whole list for viewing
$product_list = "";
$sql = mysql_query("SELECT * FROM products");
$productCount = mysql_num_rows($sql);//count the the output ammount
if ($productCount > 0){
while($row = mysql_fetch_array($sql)){
echo '<pre>';
var_dump($row);
echo '</pre>';
}

}else{
$product_list = "You have no products listed in your store Yet";
}

 

Also to clarify something, you were on the right track doing

$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));

 

As doing

 

$date_added = strftime("%b %d, %Y", strtotime($date_added));

 

is accessing $date_added before it exists.

 

The date_added field is going to be just like any of the other fields in your database (id, product_name, etc).

Link to comment
Share on other sites

there is no returned error

 

just this appears at the top of the page when viewed through browser

 

 

array

0 => string '9' (length=1)

'id' => string '9' (length=1)

1 => string 'hat' (length=3)

'product_name' => string 'hat' (length=3)

2 => string '10' (length=2)

'price' => string '10' (length=2)

3 => string 'brill' (length=5)

'details' => string 'brill' (length=5)

4 => string 'Clothing' (length=8)

'category' => string 'Clothing' (length=8)

5 => string 'Hats' (length=4)

'subcategory' => string 'Hats' (length=4)

6 => string '2011-09-28' (length=10)

'date_Added' => string '2011-09-28' (length=10)

Link to comment
Share on other sites

there is no returned error

 

just this appears at the top of the page when viewed through browser

 

 

array

0 => string '9' (length=1)

'id' => string '9' (length=1)

1 => string 'hat' (length=3)

'product_name' => string 'hat' (length=3)

2 => string '10' (length=2)

'price' => string '10' (length=2)

3 => string 'brill' (length=5)

'details' => string 'brill' (length=5)

4 => string 'Clothing' (length=8)

'category' => string 'Clothing' (length=8)

5 => string 'Hats' (length=4)

'subcategory' => string 'Hats' (length=4)

6 => string '2011-09-28' (length=10)

'date_Added' => string '2011-09-28' (length=10)

 

I think I might see your problem.

 

First off, the var_dump helps you debug your application, in this case it might have pointed something out that could be the problem.

 

mysql_fetch_array() by default does MYSQL_BOTH for return (Both numeric and associative arrays). So stripping out the numeric and leaving the associative ones for readability we come up with:

(Note: If you don't know what I'm talking about with the MYSQL_BOTH, numeric and associative array stuff read: http://us.php.net/manual/en/function.mysql-fetch-array.php )

 

array (
'id' => string '9' (length=1)
'product_name' => string 'hat' (length=3)
'price' => string '10' (length=2)
'details' => string 'brill' (length=5)
'category' => string 'Clothing' (length=8)
'subcategory' => string 'Hats' (length=4)
'date_Added' => string '2011-09-28' (length=10) 
)

 

If you look at the last one, the field appears to be named

date_Added // Notice the upper case A in Added

 

and not

 

date_added // lower case a in added

 

 

So then your code for displaying the date should be:

<?php
//This block grabs the whole list for viewing
$product_list = "";
$sql = mysql_query("SELECT * FROM products");
$productCount = mysql_num_rows($sql);//count the the output ammount
if ($productCount > 0){
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$price = $row["price"];
$product_name = $row["product_name"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_Added"])); // Notice here how we changed it from _added to _Added
$product_list .= "$id-$product_name    <a href='#'>edit</a> •<a href='#'>  delete</a><br/>";
}

}else{
$product_list = "You have no products listed in your store Yet";
}
?>

 

 

 

Also, var_dump basically prints out the contents and variable type. So something like

<?php
$somevar = 10;
vardump($somevar);
?>

 

would print out something like:

int(10)

 

 

To learn more about var_dump I would recommend reading: http://us.php.net/manual/en/function.var-dump.php I find it very useful for debugging some stuff.

 

 

Try that and see if it helps :)

Link to comment
Share on other sites

<?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 everyhting 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 varequals 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

header("location: ../index.php");

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 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 ammount

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, Price, details, category, subcategory, date_added) VALUES('$product_name','$price','$details','$category','$subcategory',now())") or die (mysql_error()); //now adds todays date

$id = 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 the output ammount

if ($productCount > 0){

while($row = mysql_fetch_array($sql)){

$id = $row["id"];

$product_name = $row["product_name"];

$date_added = strftime("%b %d, %Y", strtotime($date_Added));

$product_list .= "$id-$product_name    <a href='#'>edit</a> •<a href='#'>  delete</a><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" />

<style type="text/css">

body {

background-color: #FFF;

}

</style>

</head>

 

<body>

<div align="center"></div>

<div align="center" id="mainWrapper">

 

 

 

<?php include_once("../template_header.php"); ?>

 

<?php include_once("../template_sidebar.php"); ?>

 

 

 

 

 

<div align="left" id="pageContent">

<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 />

 

<div>

<a name="inventoryForm" id="inventoryForm"></a>

<h3 align="center">

↓ Add New Inventory Item Form ↓

</h3>

</div>

<form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myform" method="post">

<table width="90%" border="0" cellspacing="0" cellpadding="6">

<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></td>

</tr>

<tr>

<td align="right">Product Price</td>

<td><label>

£ <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="Clothing">Clothing</option>

</select>

</label></td>

</tr>

<tr>

<td align="right">Subcategory</td>

<td><select name="subcategory" id="subcategory">

<option value=""></option>

<option value="Hats">Hats</option>

<option value="Pants">Pants</option>

<option value="Shirts">Shirts</option>

</select></td>

</tr>

<tr>

<td align="right">Product Details</td>

<td><label>

<textarea name="details" id="details" cols="64" rows="5"></textarea>

</label></td>

</tr>

<tr>

<td align="right">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>

 

 

 

<br/>

<br/>

</div>

<?php include_once("../template_footer.php"); ?>

 

 

</div>

</body>

</html>

Edited by talos
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
 Share

×
×
  • Create New...