2013-12-16 87 views
0

我希望你能給我一個我無法弄清楚的建議。我正在嘗試爲我爲項目創建的數據庫創建更新功能。我希望它和我創建的插入和刪除功能一樣,但我不知所措...... 這是我創建的。更新功能不起作用

<!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> 

回答

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'"); 
0

我不知道你的數據庫建立,但在數據庫中更新定位姓氏是不好的做法之一,因爲我們不知道有與同一姓氏的數據。改爲使用Id's

在您的代碼中,您的where語句中缺少=。它應該是,

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

希望它可以幫助

+0

的問題,雖然是有脫節的地方。我有它顯示的第一個,最後一個和特許經營的名字,但它沒有給我一些更新。希望這是有道理的? – user3105751