简体   繁体   English

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

[英]Slim Php Mysql Put method empty value,want to update 4 column,but only 1 column is updated but result indicate success

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. 我的目标是在单个查询中更新表中的4列。但是最终只更新了1列,而其他3则没有更新。

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 我在高级Rest Client中运行后,带有以下查询

user_bio=hihi&gender=f&profile_image_string=somestringhere&date_of_birth=2015-08-16 user_bio =日冰&性别= F&profile_image_string = somestringhere&DATE_OF_BIRTH = 2015年8月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. 运行查询后,结果始终为“成功”,但是在Mysql表中仅更新了profile_image_path列,其余3列user_biodate_of_birthgender均未更新。

Here is my 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 更新:我尝试使用bind_param$date_of_birth s ,但仍然没有运气

$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 更新我实际上使用了来自Androidhive的此示例,示例代码如下

       /**
     * 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 但是我使用与下面相同的方法来获取值,但是在var_dump()之后所有值都是NULL是我的代码

$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 . 我也尝试这样做user_biogenderdate_of_birth值仍然为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 更新我在邮递员中通过发送带有x-www-form-urlencoded的数据进行测试后,出现了此错误,我无法获得任何解决方案

微小错误

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM