我正在制作一个api,可以帮助用户按照输入数据更新他们的信息.但是当输入json有字段"password"时它会成功更新但是当json没有这个字段时我无法更新数据库中的数据.这是我用来更新数据的代码:
public function updateUserInfo(Request $request){
$postData = $request->all();
$data = json_decode($postData['postData'], true);
if(isset($data['password'])){
$data['password'] = bcrypt($data['password']);
}
$popData = $data['UserId'];
unset($data['UserId']);
$updateInfo = array();
foreach($data as $info){
if($info != null){
$updateInfo[] = $info;
}
}
$result = DB::update(GeneralFunctions::makeUpdateString($data, 'User', ' UserId = '.$popData), $updateInfo);
if($result != null && $result == true){
return response()->json(['success'=>true, 'data'=>'Update Successful']);
}else{
return response()->json(['success'=>false, 'error'=>'We have encountered an error, try again later!']);
}
}
Run Code Online (Sandbox Code Playgroud)
当一切正常时,这是json:
$postData = '{ "UserId" : "1", "password":"12345", "UserName": "minhkhang", "Address": "11/200" …Run Code Online (Sandbox Code Playgroud) 我想用ajax或json将数据点添加到我的折线图中,现在我必须重新加载整个网页以在图表上显示我的新数据.但我想通过添加像这些链接的点来显示实时数据:
www.highcharts.com/studies/live-server.htm
我试图从mysql中检索我的数据以通过json添加到图表上但没有任何反应.这是我在live-server-data.php中的代码:
<?php
header("Content-type: text/json");
include_once 'include/connection.php';
$db = new DB_Class();
$query = "select distinct idchip from datatable ";
$result = mysql_query( $query );
$rows = array();
$count = 0;
while( $row = mysql_fetch_array( $result ) ) {
$SQL1 = "SELECT datetime,temperature FROM `datatable` WHERE idchip=".$row['0']." datetime DESC limit 0,1 ";
$result1 = mysql_query($SQL1);
while ($rows = mysql_fetch_array($result1)) {
$data[] = $rows['1'];
$datatime[] = 'moment('.$rows['0'].').valueOf()';
}
// The x value is the current JavaScript time, which is the …Run Code Online (Sandbox Code Playgroud)