致命错误:未捕获异常'PDOException',消息'SQLSTATE [HY093]:参数号无效:参数未定义'in

时间:2016-12-11 06:56:01

标签: php mysql sql

错误讯息:

  

致命错误:未捕获异常'PDOException',消息'SQLSTATE [HY093]:参数号无效:参数未定义'在/home/u410366608/public_html/admin/items.php:210堆栈跟踪:#0 / home /u410366608/public_html/admin/items.php(210):210行/home/u410366608/public_html/admin/items.php中抛出PDOStatement->执行(数组)#1 {main}

代码:

                if (empty($formErrors)) {

                    $stmt = $con->prepare("INSERT INTO items(Namea, Descriptiona, Pricea, Add_Datea, Country_Madea, Statusa, Cat_IDa, Member_IDa)
                    VALUES(:zname, :zdesc, :zprice, now(), :zcountry, :zstatus, :zcat, :member)");

                    $stmt->execute(array(

                        'zname'     => $name,
                        'zdesc'     => $desc,
                        'zprice'    => $price,
                        'zcountry'  => $country,
                        'zstatus'   => $status,
                        'zcat'      =>$cat,
                        'zmember'   =>$member

                    ));

                    echo "<div class='container'>";
                    $theMsg = "<div class='alert alert-success'>" . $stmt->rowCount() . 'Preke prideta.</div>';
                    redirectHome($theMsg, 'back' );
                    echo "</div>";      
                }

2 个答案:

答案 0 :(得分:0)

使用此代码数组并更改:zmember而不是:member

if (empty($formErrors)) {

    $stmt = $con->prepare("INSERT INTO items(Namea, Descriptiona, Pricea, Add_Datea, Country_Madea, Statusa, Cat_IDa, Member_IDa)
         VALUES(:zname, :zdesc, :zprice, now(), :zcountry, :zstatus, :zcat, :zmember)");

    $stmt->execute(array(
        ':zname'     => $name,
        ':zdesc'     => $desc,
        ':zprice'    => $price,
        ':zcountry'  => $country,
        ':zstatus'   => $status,
        ':zcat'      =>$cat,
        ':zmember'   =>$member
    ));

    echo "<div class='container'>";
    $theMsg = "<div class='alert alert-success'>" . $stmt->rowCount() . 'Preke prideta.</div>';
    redirectHome($theMsg, 'back' );
    echo "</div>";      
}

答案 1 :(得分:0)

在您使用的语句中:member和您使用的关联数组

'zmember' =>$member,将'zmember' =>$member更改为'member' =>$member 这将解决问题。