php mysql IN clause not working with CSV variable. only first row is affected

落花浮王杯 提交于 2021-02-08 11:55:50

问题


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:


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)"



来源:https://stackoverflow.com/questions/26901609/php-mysql-in-clause-not-working-with-csv-variable-only-first-row-is-affected

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!