[56K WARN] Update Record with select menu
Posted: Thu Nov 02, 2006 4:05 pm
I am buildiing an admin area to manage a list of articles. Each article has a status which can either be current (0) or archived (1). I have both of these options in a slect menu. I want to be able to update the record when choosing the status in the select menu. The code I wrote seems ok but I don't know if I have to specify the id in the menu options (nor do I understand how).
Update code:
display / loop code:
Thanks,
Pete
Update code:
Code: Select all
<?php
ob_start();
include '../includes/connect.php';
if(isset($_POST['update'])) {
$status = $_POST['status'];
$query = "UPDATE article SET status='$status' WHERE a_id='$a_id'";
mysql_query($query) or die (mysql_error());
mysql_close();
header ('location:index.php');
}
?>Code: Select all
<?php
include '../includes/connect.php';
$query = "select * FROM article ORDER BY a_id";
$result = mysql_query($query);
mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$a_id = $row['a_id'];
$title = $row['title'];
$status = $row['status'];
echo '<li><p><a href="view.php?a_id=' . $a_id . '">' . $title . '</a><br />';
echo '<a href="#a_id=' . $a_id . '">Edit</a> - ';
echo '<a href="delete.php?a_id=' . $a_id . '">Delete</a><br />';
echo '<form method="post">';
echo 'Status: ';
switch ($status) {
case 0:
echo '<select><option value="0" selected="selected">Current</option><option value="1">Archive</option></select>';
break;
case 1:
echo '<select><option value="0">Current</option><option value="1" selected="selected">Archive</option></select>';
break;
}
echo '<input type="submit" name="update" value="Update">';
echo '</form>';
}
?>Pete
[/img]