我正在尝试更新我能够查看的值。它似乎没有错误,但似乎没有任何更新。任何人都可以帮我确定它没有更新的地方吗?请
<?php
// check for errors
ini_set('display_errors', 1);
//calls connection
require_once('connection.php');
//view first table
$ResultSets = getResults("members");
echo "<table border='1' cellpadding='6'>";
echo "<tr> <th>member_id</th> <th>first_name</th> <th>second_name</th> <th>Email</th> ";
foreach ($ResultSets as $record) {
echo "<form action=index.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=text name=topic value =" . $record ['member_id'] . " </td>";
echo "<td>" . "<input type=text name=topic value =" . $record ['first_name'] . " </td>";
echo "<td>" . "<input type=text name=topic value =" . $record ['second_name'] . " </td>";
echo "<td>" . "<input type=text name=topic value =" . $record ['email'] . " </td>";
echo "<td>" . "<input type=hidden name=hidden value =" . $record ['member_id'] . " </td>";
//echo "</tr>";
echo "<input type=submit name=update value=Update>" . " </td>";
}
echo "<table>";
echo "</form>";
if (isset($_POST['update'])) {
$updateQuery = "UPDATE members SET first_name='$_POST[first_name]', second_name='$_POST[second_name]', email='$_POST[email]' WHERE member_id='$_POST[hidden]'";
mysql_query($updateQuery);
}
?>
答案 0 :(得分:1)
您的所有输入都有主题名称。
echo "<td>" . "<input type=text name=topic value =" . $record ['member_id'] . " </td>";
echo "<td>" . "<input type=text name=topic value =" . $record ['first_name'] . " </td>";
echo "<td>" . "<input type=text name=topic value =" . $record ['second_name'] . " </td>";
echo "<td>" . "<input type=text name=topic value =" . $record ['email'] . " </td>";
需要更改为
echo "<td>" . "<input type=text name=member_id value =" . $record ['member_id'] . " </td>";
echo "<td>" . "<input type=text name=first_name value =" . $record ['first_name'] . " </td>";
echo "<td>" . "<input type=text name=second_name value =" . $record ['second_name'] . " </td>";
echo "<td>" . "<input type=text name=email value =" . $record ['email'] . " </td>";
答案 1 :(得分:1)
此外,您还将member_id
作为字符串传递,而我确定它是数据库中的整数。尝试:
$updateQuery = "UPDATE members SET first_name='$_POST[first_name]', second_name='$_POST[second_name]', email='$_POST[email]' WHERE member_id=$_POST[hidden]";