对于这里的业余问题,我很抱歉,但我已经创建了一个表单,在我的一生中,我无法调试它为什么不会将更新提交到数据库中的原因。
一个例子在这里:www.dominicharrison.co.uk/projects/Portfolio/admin
代码:
<?php
require_once('../_inc/glob.php');
$query = mysql_query("SELECT * FROM `pages`");
echo "<table border=\"1\"><tr><td>ID</td><td>Name</td><td>Location</td><td>Edit</td><td>Delete</td></tr>";
while($array = mysql_fetch_assoc($query)) {
echo "<tr><td>" . $array['id'] . "</td><td>" . $array['name'] . "</td><td>" . $array['location'];
echo "</td><td><a href=\"?editid={$array['id']}\">Edit</a></td>";
echo "<td><a href=\"?delete={$array['id']}\">Delete</a></td></tr>";
}
echo "</table>";
// Defines the edit and delete functions
$edit = mysql_real_escape_string($_GET['editid']);
$delete = mysql_real_escape_string($_GET['delete']);
// Edit function!
$query2 = mysql_query("SELECT * FROM `pages` WHERE `id` = '{$edit}'");
$array2 = mysql_fetch_assoc($query2);
if($edit != "") {
?>
<p>
<form method="POST" action="">
<input name="name" value="<?php echo $array2['name']; ?>" type="text"><br />
<input name="location" value="<?php echo $array2['location']; ?>" type="text"><br />
<input type="submit" value="Edit!">
</form></p>
<?php
if($_POST['submit'])
{
$name = mysql_real_escape_string($_POST['name']);
$location = mysql_real_escape_string($_POST['location']);
mysql_query("UPDATE `pages` SET id = '{$edit}', name = '{$name}', location = '{$location}' WHERE id = '{$edit}'");
}
}