我正在尝试更新一些数据并且它返回正常,但在我的数据库中没有任何变化:
<?php
function updater($value, $id){
// Create connection
$conn = new mysqli( 'localhost' , 'webjgb_updter' , 'upDat3r*' ,'webjgb_updtst' );
$value =mysqli_real_escape_string($conn,$value);
$id =mysqli_real_escape_string($conn,$id);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE editinplace SET nombre='{$value}', apellidos='{$value}', email='{$value}', telefono='{$value}' WHERE id='{$id}'";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
}
if(isset($_POST['nombre']))
updater($_POST['nombre'],$_POST['id'])
?>
答案 0 :(得分:0)
这可能是因为IF未执行:
;
答案 1 :(得分:0)
这里有一个错误,if-clause
什么都不做。它就在那里:
if(isset($_POST['nombre']))
updater($_POST['nombre'],$_POST['id'])
将其更改为:
↓
if(isset($_POST['nombre'])) {
updater($_POST['nombre'],$_POST['id']) }
↑
我已将'{$value}'
更改为'".$value."'
这是更正后的脚本:
<?php
function updater($value, $id){
// Create connection
$conn = new mysqli( 'localhost' , 'webjgb_updter' , 'upDat3r*' ,'webjgb_updtst' );
$value =mysqli_real_escape_string($conn,$value);
$id =mysqli_real_escape_string($conn,$id);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE editinplace SET nombre='".$value."', apellidos='".$value."', email='".$value."', telefono='".$value."' WHERE id=".$id."";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
}
else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
}
if(isset($_POST['nombre'])) {
updater($_POST['nombre'],$_POST['id'])
}
?>