-1

我想从数据库更新我的数据,但不幸的是我无法更新。有谁能帮助我。

我将不胜感激。

问题是当我的代码出错时无法显示错误。对不起,我的英语不好。

这是我的代码

<?
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';
}
?>
4

3 回答 3

0

请在此之后删除逗号,

Year_Birth_Person = '$yearbirth'
于 2013-10-29T08:36:50.353 回答
0

我猜你的表中没有 ID_Person == $id 的 T_Person 所以没有更新

于 2013-10-29T11:42:09.257 回答
0

您的查询中有一个错误,前面带有逗号WHERE

$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',
                                                                 no comma here   ^
                                              WHERE ID_Person = '$id'");

尝试echo在 PHP 中查询您的查询并将此查询复制粘贴到 phpMyAdmin 中。

于 2013-10-29T08:35:09.170 回答