juraganerka Posted October 30, 2013 Share Posted October 30, 2013 i want to update my database,but unfortunately not change. anyone can help me.i can't solved it over 1 week.please. this is my code: <? include "new.php"; $response = array(); if (isset($_GET['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 = $_GET ['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']; $query = "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'"; $hasil = sqlsrv_query($conn,$query,$response); $rows_affected = sqlsrv_rows_affected($hasil); if ($rows_affected() === false) { // jika gagal update $response["sukses"] = 1; $response["pesan"] = "Member berhasil diupdate"; // memprint/mencetak JSON respon echo json_encode($response); } else { // jika gagal di update $response["sukses"] = 0; $response["pesan"] = "Gagal update"; // memprint/mencetak JSON respon echo json_encode($response); } } else { // jika data tidak terisi/tidak terset $response["sukses"] = 0; $response["pesan"] = "data belum terisi"; // memprint/mencetak JSON respon echo json_encode($response); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/283427-can-update-database/ Share on other sites More sharing options...
mentalist Posted October 30, 2013 Share Posted October 30, 2013 What's in new.php? Does it start the db connection? Quote Link to comment https://forums.phpfreaks.com/topic/283427-can-update-database/#findComment-1456168 Share on other sites More sharing options...
Ch0cu3r Posted October 30, 2013 Share Posted October 30, 2013 (edited) Your trying to call a function here. if ($rows_affected() === false) The variable $rows_affected contains the number of rows the query updated. Not a function  It should be if ($rows_affected !== false) Edited October 30, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283427-can-update-database/#findComment-1456169 Share on other sites More sharing options...
juraganerka Posted October 31, 2013 Author Share Posted October 31, 2013 What's in new.php? Does it start the db connection? new.php is connection with database.it's same like db connection Quote Link to comment https://forums.phpfreaks.com/topic/283427-can-update-database/#findComment-1456296 Share on other sites More sharing options...
juraganerka Posted October 31, 2013 Author Share Posted October 31, 2013  Your trying to call a function here. if ($rows_affected() === false) The variable $rows_affected contains the number of rows the query updated. Not a function  It should be if ($rows_affected !== false) i try change what u suggest but it's not working Quote Link to comment https://forums.phpfreaks.com/topic/283427-can-update-database/#findComment-1456297 Share on other sites More sharing options...
mac_gyver Posted October 31, 2013 Share Posted October 31, 2013 are you getting the message your code produces (Gagal update) or is your database just not updating when you look in it? Quote Link to comment https://forums.phpfreaks.com/topic/283427-can-update-database/#findComment-1456299 Share on other sites More sharing options...
juraganerka Posted October 31, 2013 Author Share Posted October 31, 2013 are you getting the message your code produces (Gagal update) or is your database just not updating when you look in it? my database not updated when i execute that query Quote Link to comment https://forums.phpfreaks.com/topic/283427-can-update-database/#findComment-1456303 Share on other sites More sharing options...
Ch0cu3r Posted October 31, 2013 Share Posted October 31, 2013 How is this PHP code being called? I am guessing this is part of an Ajax request? Quote Link to comment https://forums.phpfreaks.com/topic/283427-can-update-database/#findComment-1456325 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.