我想从数据库更新我的数据,但不幸的是我无法更新。有谁能帮助我。
我将不胜感激。
问题是当我的代码出错时无法显示错误。对不起,我的英语不好。
这是我的代码
<?
include "new.php";
$response = array("updated data", 1);
if (isset($_POST['ID_Person']) && isset($_POST['FirstName']) && isset($_POST['MiddleName']) && isset($_POST['LastName']) && isset($_POST['AliasName'])
&& isset($_POST['Gender']) && isset($_POST['CityBirth']) && isset($_POST['DateBirth']) && isset($_POST['MonthBirth']) && isset($_POST['YearBirth']))
{
$id = $_POST['ID_Person'];
$name = $_POST['FirstName'];
$middle = $_POST['MiddleName'];
$last = $_POST['LastName'];
$alias = $_POST['AliasName'];
$gender = $_POST['Gender'];
$citybirth = $_POST['CityBirth'];
$datebirth = $_POST['DateBirth'];
$monthbirth = $_POST['MonthBirth'];
$yearbirth = $_POST['YearBirth'];
$hasil = sqlsrv_query($conn,"UPDATE T_Person SET
First_Name_Person = '$name' ,
Middle_Name_Person = '$middle' ,
Last_Name_Person = '$last' ,
Alias_Person = '$alias',
Gender_Person = '$gender',
City_Birth_Person = '$citybirth',
Date_Birth_Person = '$datebirth',
Month_Birth_Person = '$monthbirth',
Year_Birth_Person = '$yearbirth',
WHERE ID_Person = '$id'"
);
$rows_affected = sqlsrv_rows_affected($hasil);
if ($rows_affected === false)
{
die( print_r( sqlsrv_errors(), true));
}
if ($hasil)
{
$response["success"] = 1;
$response["message"] = "Product successfully edit.";
// echoing JSON response
echo json_encode($response);
}
}
else {
echo 'Data fail update';
}
?>