php mysql IN子句不适用于CSV变量.仅第一行受到影响 [英] php mysql IN clause not working with CSV variable. only first row is affected

查看:40
本文介绍了php mysql IN子句不适用于CSV变量.仅第一行受到影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用php我的管理员查询数据库时,以下sql起作用

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)

我有一个文本框,用户可以在其中输入用逗号分隔的数字.这是通过邮寄提交到$ invoice变量的.当我运行以下内容时,仅第一行受到影响.被注释掉的代码是我尝试过但无法正常工作的事情

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概率缺少一些简单的

im probability missing something simple

p.s.当我只输入一个值,因此它不是无效的日期或其他任何内容时,它也可以工作

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

推荐答案

不要在$ invoice中使用'',因为当您使用它时,它就像'1,2,3',而它应该像'1','2','3'或1,2,3

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

我认为您的查询应如下

更新已付款的发票集= 1,date_recieved ='$ date',check_number ='$ check',其中invoice_number IN($发票)"

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

这篇关于php mysql IN子句不适用于CSV变量.仅第一行受到影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆