更新功能不起作用

时间:2013-12-16 01:49:53

标签: php html mysql

我希望你能给我一个我无法弄清楚的建议。我正在尝试为我为项目创建的数据库创建更新功能。我希望它就像我创建的插入和删除功能一样,但我不知所措...... 这就是我创造的。

<!DOCTYPE html>
<html>
<body>


<h1>Franchise Call Log</h1>

<?php
$con=mysqli_connect("","","","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM caller_info");

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Franchise</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Firstname'] . "</td>";
echo "<td>" . $row['Lastname'] . "</td>";
echo "<td>" . $row['Franchise'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?> 

</body>
</html> 

<h1>Insert a New Caller</h1>
<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname">
Lastname: <input type="text" name="lastname">
Franchise: <input type="text" name="franchise">
<input type="submit" name="submit">
</form>

</body>
</html>

<html>
<body>

<h1>Delete a Caller</h1>
<form action="delete.php" method="post">
Lastname: <input type="text" name="lastname">
<input type="submit" name="submit">
</form>

</body>
</html>

<html>
<body>

<h1>Update a Caller</h1>
<form action="update.php" method="post">
Firstname: <input type="text" name="firstname">
Lastname: <input type="text" name="lastname">
Franchise: <input type="text" name="franchise">
<input type="submit" name="submit">
</form>

</body>
</html>

<!DOCTYPE html>
<html>
<body>

<h1>Your records have been updated</h1>

<?php
$con=mysqli_connect("");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con,"UPDATE Caller_info SET Firstname = '$firstname' WHERE Lastname '$lastname'");

mysqli_close($con);
?> 

</body>
</html>

2 个答案:

答案 0 :(得分:1)

你缺少=在更新声明中签名。

mysqli_query($con,"UPDATE Caller_info SET Firstname = '$firstname' WHERE Lastname '$lastname'");

mysqli_query($con,"UPDATE Caller_info SET Firstname = '$firstname' WHERE Lastname = '$lastname'");

答案 1 :(得分:0)

我不知道您的数据库设置,但在数据库更新中定位lastname是一种不好的做法,因为我们不知道有相同姓氏的数据。请改用Id's

在您的代码中,您的where语句中缺少=。它应该是,

mysqli_query($con,"UPDATE Caller_info SET Firstname = '$firstname' WHERE Lastname = '$lastname'");

希望有所帮助