cant update table
Posted: Tue Mar 25, 2008 12:58 pm
I know its not the best way of coding but my delete and insert work but not update .. can anyone tell me what i could be doing wrong ?
Code: Select all
<?PHP
require_once($_SERVER['DOCUMENT_ROOT'] . 'db.php');
header("Pragma: nocache");// HTTP/1.0
header("Cache-Control: no-cache, must-revalidate");
$clid = "342";
if ($submit) {
// here if no ID then adding else we're editing
echo $attribute_id;
if (!$attribute_id) {
$sql = "INSERT INTO product_attributes (clid,attribute_name,price,url,sort) VALUES ('$clid', '$attribute_name', '$price', '$url','$sort')";
} elseif ($update) {
$sql = "UPDATE product_attributes SET (attribute_id='$attribute_id',clid='$clid',price='$price',url='$url',sort='$sort')WHERE attribute_id=$attribute_id";
}
$result = mysql_query($sql);
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM product_attributes WHERE attribute_id=$attribute_id";
$result = mysql_query($sql);
} else {
// this part happens if we don't press submit
if (!$attribute_id) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM product_attributes WHERE clid=" . $clid . " ORDER BY sort ASC");
while ($myrow = mysql_fetch_array($result)) {
echo '<input type="text" name="attribute_name" value="' . $myrow["attribute_name"] . '"><input type="text" name="price" value="' . $myrow["price"] . '"><input type="text" name="url" value="' . $myrow["url"] . '"><input type="text" name="sort" size="3" value="' . $myrow["sort"] . '">';
printf("<a href=\"%s?attribute_id=%s&delete=yes\">(DELETE)</a>", $PHP_SELF, $myrow["attribute_id"]);
printf("<a href=\"%s?attribute_id=%s&update=yes\">(UPDATE)</a><BR>", $PHP_SELF, $myrow["attribute_id"]);
}
}
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if (!$attribute_id) {
// editing so select a record
$sql = "SELECT * FROM product_attributes WHERE clid=$clid ORDER by sort ASC";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$clid = $myrow["clid"];
$attribute_name = $myrow["attribute_name"];
$price = $myrow["price"];
$url = $myrow["url"];
// print the id for editing
?>
<?php
}
?>
<input type="hidden" name="clid" value="<?php echo $clid ?>"><br>
Attribute:<input type="Text" name="attribute_name"><br>
Price:<input type="Text" name="price"><br>
URL:<input type="Text" name="url"><br>
Order:<input type="Text" name="sort"><br>
<input type="Submit" name="submit" value="Add new row">
</form>
<?php
}
?>
</body>
</html>