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

edit:

//insert content
mysql_query("INSERT INTO tuck (item, price, newchk) VALUES ('$ucname','$_POST[price]','$newchk')") or die(mysql_error());

if ($noitems['newchk'] == 1) {
	mysql_query("UPDATE tuck SET new='NEW'");
}

echo "Item added";

adds the state of newchk into the database, but now i need the value of 'new' i nthe database to be filled with "NEW" if the chk == 1


EDIT: Got it all working now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.