hi guys
Just wipped up this script too
but its not inserting data can anyone see why? I do not get any error messages
i Have a table called event_categories and two columns in it categoryID and category
<html>
<body>
<?php
$db = mysql_connect("localhost", "phpuser", "phpuser03");
mysql_select_db("booking",$db);
if ($submit) {
// here if no ID then adding else we're editing
if ($categoryID) {
$sql = "UPDATE event_categories SET category='$category' WHERE categoryID=$categoryID";
} else {
$sql = "INSERT INTO event_categories (category) VALUES ('$category')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Record updated/edited!<p>";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM event_categories WHERE categoryID=$categoryID";
$result = mysql_query($sql);
echo "$sql Record deleted!<p>";
} else {
// this part happens if we don't press submit
if (!$categoryID) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM event_categories",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=\"%s?categoryID=%s\"> %s</a><br>\n", $PHP_SELF, $myrow["categoryID"], $myrow["category"]);
printf("<a href=\"%s?categoryID=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["categoryID"]);
}
}
?>
<P>
<a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<P>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($categoryID) {
// editing so select a record
$sql = "SELECT * FROM event_categories WHERE categoryID=$categoryID";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$categoryID = $myrow["categoryID"];
$category = $myrow["category"];
// print the id for editing
?>
<input type=hidden name="categoryID" value="<?php echo $categoryID ?>">
<?php
}
?>
Categories:<input type="Text" name="category" value="<?php echo $category ?>"><br>
<br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}
?>
</body>
</html>