duanao2585 2017-02-28 10:46
浏览 34

Slim Php Mysql Put方法空值,想要更新4列,但只更新1列但结果表明成功

My goal is to update 4 column in my table in a single query.But end up only 1 column is updated,the other 3 is not.

My query is like this

$stmt = $this->conn->prepare("UPDATE users_info SET profile_image_path = ?,user_bio = ? ,gender = ?,date_of_birth = ? WHERE user_id = ?");
$stmt->bind_param("sssii",$profile_image_upload_url,$user_bio,$gender,$date_of_birth,$user_id);
$result = $stmt->execute();
$stmt->close();
return $result;

Here is my code for the query call

//update to database
global $user_id;
$db = new DBhandler();
$update_result = $db->callForQueryFunction($user_id,$user_bio,$date_of_birth,$gender,$profile_image_string);
$response = array();

if($update_result){
    $response['error'] = false;
    $response['message'] ="sucess";
}else{
    $response['error'] = true;
    $response['message'] ="fail";
}

After I run in advanced rest client ,with the the following query

user_bio=hihi&gender=f&profile_image_string=somestringhere&date_of_birth=2015-08-16

After run the query,the result is always "success",but in Mysql table only profile_image_path column is updated,the rest 3 column user_bio,date_of_birth and gender all are not updated.

Here is my database structure database structure

I work for hours still haven't figure it out what's wrong with the code or my database structure.

Update: I tried with bind_param for s with $date_of_birth,but still no luck with it

$stmt->bind_param("ssssi",$profile_image_upload_url,$user_bio,$gender,$date_of_birth,$user_id);

UPDATE I actually using this example from Androidhive,the sample code is as below

       /**
     * Updating existing task
     * method PUT
     * params task, status
     * url - /tasks/:id
     */

$app->put('/tasks/:id', 'authenticate', function($task_id) use($app) {
            // check for required params
            verifyRequiredParams(array('task', 'status'));

            global $user_id;            
            $task = $app->request->put('task');
            $status = $app->request->put('status');

But I use the same method as below to grab the value,but after var_dump() all the value is NULL.Here is my code

$app->put('/updateuserdetails','authenticate',function ()use ($app){

$user_bio  = $app->request()->put('userbio');
$gender    =$app->request()->put('gender');
$date_of_birth = $app->request()->put('dob');
$profile_image_string = $app->request()->put('profilestring');

I try this as well.The value of user_bio,gender,date_of_birth are all still null.

$app->post('/updateuserdetails','authenticate',function ()use ($app){

$user_bio  = $app->request()->post('userbio');
$gender    =$app->request()->post('gender');
$date_of_birth = $app->request()->post('dob');
$profile_image_string = $app->request()->post('profilestring');

I just cant figure out what is going wrong here

Update After I test it in Postman by send data with x-www-form-urlencoded it come out with this error,which I cant get any solution

slim error

  • 写回答

1条回答 默认 最新

  • dousong4777 2017-02-28 11:02
    关注

    Try the following:

    $stmt = $this->conn->prepare("UPDATE users_info SET profile_image_path = :image, user_bio = :bio, gender = :gender, date_of_birth = :dob WHERE user_id = :id");
    
    $stmt->bindParam(":image", $profile_image_upload_url, PDO::PARAM_STR);
    $stmt->bindParam(":bio", $user_bio, PDO::PARAM_STR);
    $stmt->bindParam(":gender", $gender, PDO::PARAM_STR);
    $stmt->bindParam(":dob", $date_of_birth, PDO::PARAM_STR);
    $stmt->bindParam(":id", $user_id, PDO::PARAM_INT);
    
    $result = $stmt->execute();
    
    $stmt->close();
    
    return $result;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂