doupuzhimuhan9216 2015-05-14 09:41
浏览 35
已采纳

MySQL“UPDATE”语法在列中输入0

I am trying to enter into a table in with PDO if using an if condition. My code for the function is below:

function add_user_info($conn, $user, $info, $fName, $sName, $past, $pos){
    // Prepare and execute statements
    $info1 = addslashes($info);

    $sql = $conn->prepare("SELECT * FROM `User_Info` WHERE `User` = '$user'");
    $sql->execute();
    if ($sql->fetch()){
        // Update current entry
        $sql1 = $conn->prepare("UPDATE `User_Info` SET `Info` = '$info1' AND `Past` = '$past' AND `Position` = '$pos' WHERE `User` = '$user'");
    } else {
        // Create new entry
        $sql1 = $conn->prepare("INSERT INTO `User_Info` (`User`, `Info`, `FName`, `SName`, `Past`, `Position`) VALUES ('$user', '$info1', '$fName', '$sName', '$past', '$pos')");
    }
    $sql1->execute();
}

The ONLY (I repeat, ONLY) part that is not working for me is on line 9 with the update query. I have narrowed the problem down to it being related with the update of the Info column, and not only that but it is a problem with the string so the variable $info1.

I am trying to pass in a string of text from CKEditor. It is a rich text string and so has HTML tags, quotations, etc in it when passed to the SQL.

The initial creation of the row in the table (line 12 of the function) works PERFECTLY so it is only on the update that the string is seen as funny. When I update with a word in place of $info1 it still does not work.

As shown in phpmyadmin, my table schema is as follows:

User_Info table schema

  • 写回答

2条回答 默认 最新

  • douqiao3930 2015-05-14 09:44
    关注

    Update command multiple set is separated by , not and

    UPDATE `User_Info` 
    SET 
    `Info` = '$info1' ,
    `Past` = '$past' ,
    `Position` = '$pos' 
    WHERE `User` = '$user'"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据