I'm trying to create a code that update some of the values in one of my row in the a table. The code works but no as well as i wanted. It changes all values of the rows instead of changing just the one that I wanted to change. For example if i'm trying change the price of one of the items, by filling the price field in the form and leaving the rest blank. But instead of updating the price only it updates the whole table with blank values, which means all the information from the table will have gone and I only wanted to change the price. How can fix this? Thanks Here is my code:
include("misc.inc");
$id = $_GET['id'];
$db = 0;
$db = mysql_connect($db_host . ":" . $db_port, $db_user, $db_pwd);
if ($db == 0) {die("Cannot connect, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};
echo "Database connection has been established successfully<br />\n";
mysql_query("USE " . $db_db);
if (mysql_errno() != 0) {die("Cannot USE database, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};
echo "Database has been selected successfully<br />\n";
if (isset($_POST['submit'])):
$itemName = $_POST ['itemName'];
$item_Description = $_POST ['item_Description'];
$price = $_POST ['price'];
$contactName = $_POST ['contactName'];
$phone = $_POST ['phone'];
$email = $_POST ['email'];
$website =$_POST ['website'];
$sql = "UPDATE items SET
itemName = '$itemName',
email = '$email',
item_description ='$item_Description',
price = '$price',
contactName = '$contactName',
phone ='$phone',
website ='$website'
WHERE items.itemID='$id'";
if (@mysql_query($sql)) {
echo('<p>Item editted successfully!</p>');
} else {
echo('<p>Error editting item!<br />'.
'Error <b>' . mysql_errno() . '</b>'. mysql_error() . '</p>');
}
?>
<p><a href="<? $_SERVER['PHP_SELF']?>" method = "POST"></a></p>
<p><a href="items.php">Return to Front Page</a></p>
</ul>