douren2831 2014-11-13 04:56
浏览 28
已采纳

php mysql IN子句不使用CSV变量。 只有第一行受到影响

when i query the database using php my admin the following sql works

update invoice
set paid = 1, date_recieved = 0000-00-00, check_number = 00000
where invoice_number IN (110038,110035,110033)

i have a text box where a user enters numbers separated by a comma. this is submitted via post to the $invoice variable. when i run the following only the first row is affected. the code commented out is things that i tried but didn't work

if(isset($_POST["paymentbtn"])){
    $invoice = $_POST["invoice"];
    //$data = array($invoice);
    //$data = implode(",", $data);
    $date = $_POST["date"];
    $check = $_POST["checknumber"];
    //$invoice = mysql_real_escape_string($invoice);
    $sql = mysql_query("update invoice set paid = 1, date_recieved = '$date',     check_number = '$check'
where invoice_number IN ('$invoice')" )or die (mysql_error());
}

im probability missing something simple

p.s. it also works when i just enter one value so its not an invalid date or anything

  • 写回答

1条回答 默认 最新

  • drd0833 2014-11-13 05:07
    关注

    Don't use ' ' for $invoice because when you use it is like '1,2,3' where it should either be like '1','2','3' or 1,2,3

    I think your query should be as below

    "update invoice set paid = 1, date_recieved = '$date', check_number = '$check' where invoice_number IN ($invoice)"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出
  • ¥30 微信小程序请求失败,网页能正常带锁访问
  • ¥15 Matlab求解微分方程,如何用fish2d进行预优?