dongtou2016 2014-09-24 21:26
浏览 69

使用数组的SQL PHP UPDATE查询

I am trying to update an MS Access table using an array here is my code

for($i = 1; $i<=$rows; $i++)
{
    $seedsize[$i]      = $_POST['packageType'.$i];
    $RefNo[$i]         = $_POST['field'.$i];
    (int)$qtyOrder[$i] = $_POST['ordered'.$i];
    (int)$qtyDel[$i]   = $_POST['delivered'.$i];
    $unitPrice[$i]     = $_POST['unitPriceDtl'.$i];
    $ref2[$i]          = $_POST['grade'.$i];
    //$date[$i]        = $_POST['myDate'.$i];
}

$InvoiceID = $_SESSION['InvoiceID'];

$sql = "UPDATE 
            [Tbl_Invoice_Details]
        SET 
            [Seed Size]=?, 
            [RefNo]=?, 
            [Quantity Ordered]=?,
            [Quantity Delivered]=?, [Ref2]=?,
            [PricePerUnit]=?
        WHERE 
            [Invoice_ID]=?";

    $data = $conn2->prepare($sql);
    for($x = 1; $x <= 4; $x++)
    {
        $data->execute(array($seedsize[$x], $RefNo[$x], $qtyOrder[$x], $qtyDel[$x], $unitPrice[$x], $ref2[$x], $InvoiceID));
        echo $RefNo[$x]."<br/>"; 
    }

I am getting this error "Invalid character value for cast specification: -3030 [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression."

Thank you for your help!

  • 写回答

2条回答 默认 最新

  • dqgg25493 2014-09-24 21:56
    关注

    Have you confirmed that there isn't any null values in the data? Null values might be causing the cast error.

    I would suggest to cast all numeric values:

    for($i = 1; $i<=$rows; $i++)
    {
        $seedsize[$i] = $_POST['packageType' . $i]; // Not sure about this one
        $RefNo[$i] = (int)$_POST['field' . $i]; 
        $qtyOrder[$i] = (int)$_POST['ordered' . $i];
        $qtyDel[$i] = (int)$_POST['delivered' . $i];
        $unitPrice[$i] = (float)$_POST['unitPriceDtl' . $i];
        $ref2[$i] = $_POST['grade' . $i]; // Not sure about this one
        //$date[$i] = $_POST['myDate' .$i];
    }
    

    Please note that the cast should be on the right side of the assignment operator.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM