Hi there,
I am looking for some help on PHP/MySQL please :)
I have a site where you add an item via a form which is then put into a mysql data base.
I was wondering if there was anyway so that on this inital form there could be a checkbox that the admin could tick when adding a new item that marks it as 'NEW' when the database is printed out as a price list.
I currently have 'new' setup as boolean on the database
e.g
add new item.
Name: Pear
Price: 15p
New?: [x]
printed out as:
Pear 15p NEW
form.html
<form action="additem.php" method="post" onsubmit="return checkAdd()">
Name: <input type = "text" name = "name" id="addname" /><br />
Price: <input type = "text" name = "price" id="addprice"/><br />
New?: <input type = "checkbox" name = "new"/><br />
<input type="submit" value="Add item"/>
additem.php
$name = $_POST['name'];
$price = $_POST['price'];
$newchk = $_POST['newchk'];
$allitems = mysql_query("SELECT * FROM tuck");
$noitems = mysql_fetch_array($allitems);
$lowcase = strtolower($name);
$ucname = ucwords($lowcase);
//insert content
mysql_query("INSERT INTO tuck (item, price) VALUES ('$ucname','$_POST[price]')") or die(mysql_error());
if ($noitems['newchk'] == 1) {
mysql_query("UPDATE tuck SET new='NEW'");
}
echo "Item added";
Thanks in advance