我在数据库中保存了一个联系人,我使用下面的代码进行更新。但是,它没有更新。我已经检查了POST
值,以确保它们不是空的。我很感激任何指导。
$conn=mysqli_connect("localhost","root", "", "contacts");
$sql = "UPDATE contact SET cont_fname='".$_POST['cont_fname']."', cont_family='".$_POST['cont_family']."', cont_phone='".$_POST['cont_phone']."' WHERE cont_id='".$_POST['cont_id']."'";
$add_contact = mysqli_query($conn, $sql) or die(mysqli_error($conn));
答案 0 :(得分:0)
备选方案1:
$sql = "UPDATE contact SET cont_fname='".$_POST[cont_fname]."',
cont_family='".$_POST[cont_family]."', cont_phone='".$_POST[cont_phone]."'
WHERE cont_id='".$_POST[cont_id]."'";
备选方案2:
$cont_fname = $_POST['cont_fname'];
$cont_family = $_POST['cont_family'];
$cont_phone = $_POST['cont_phone'];
$cont_id = $_POST['cont_id'];
$sql = "UPDATE contact SET cont_fname='$cont_fname',
cont_family='$cont_family', cont_phone='$cont_phone' WHERE cont_id='$cont_id'";
答案 1 :(得分:0)
使用此
$cont_fname = $_POST['cont_fname'];
$cont_family = $_POST['cont_family'];
$cont_phone = $_POST['cont_phone'];
$cont_id = $_POST['cont_id'];
$mysqli = new mysqli('localhost','root','','contacts');
if ($mysqli->connect_error)
{
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
//MySqli Update Query
$results = $mysqli->query("UPDATE contact SET cont_fname= '$cont_fname', cont_family ='$cont_family', cont_phone='$cont_phone' WHERE cont_id='$cont_id'");
if($results)
{
print 'Success! record updated / deleted';
}
else
{
print 'Error : ('. $mysqli->errno .') '. $mysqli->error;
}