Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in **************** on line 11这个是个购物车,当我第一次进来的时候会报个错。查了一下是是数组元素重复定义了。
但是我又知道该怎么改,麻烦大家看一下。<?php
include_once('public.inc.php');
include_once('checkuser.php');

if(isset($_POST['submitCheck']) && $_POST['submitCheck']=='ok'){
$productClassId = $db->GetClassId(PRODUCTS);
$_amout = $_totalprice = 0;
if (is_array($_POST['amounts'])) {
$_SESSION['orderlines'] = $_orderlines = array();

foreach ($_POST['amounts'] as $cp_id => $amount) {
if (0 == $amount) continue;

$cp = $db->GetOne("SELECT * FROM #@__act WHERE PID IN($productClassId) AND #@__act.id='$cp_id'");
if ($cp) {
$totalprice = $cp['price'] * $amount;
$_SESSION['orderlines'][$cp['id']] = array(
'cp_id' => $cp['id'],
'cpname' => $cp['title'],
'cpimg' => $cp['img'],
'price' => $cp['price'],
'amount' => $amount
);
$_orderlines[$cp['id']] = array(
'cp_id' => $cp['id'],
'cpname' => $cp['title'],
'cpimg' => $cp['img'],
'price' => $cp['price'],
'amount' => $amount,
'totalprice' => $totalprice
);

$_totalprice += $totalprice;
$_amout += $amount;
}
}
} else {
header('Location: shoppingCart.php');
exit();
}

if($_SESSION['dd_ckstr'] == $_POST['checkCode']){
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';

foreach(array('name', 'telephone', 'address', 'email', 'content') as $key){
$_POST[$key] = htmlentities($_POST[$key], ENT_QUOTES, 'utf-8');
}
$result = $db->ExecuteNoneQuery("INSERT INTO #@__order (`NAME`,`TEL`,`ADD`,`EMAIL`,`NOTES`,`TIME`, `totalprice`,`huiyuan`) values ('$_POST[name]','$_POST[telephone]','$_POST[address]','$_POST[email]','$_POST[content]',NOW(), '$_totalprice', '$_SESSION[account]')");
if($result){
$oid = $db->GetLastID();
foreach ($_orderlines as $cp_id => $ol) {
$db->ExecuteNoneQuery("INSERT INTO #@__orderline (`orderid`,`cp_id`,`price`,`amount`,`totalprice`,`time`) values ('$oid','$cp_id','$ol[price]','$ol[amount]','$ol[totalprice]',NOW())");
}
$_SESSION['orderlines'] = array();

echo "<script>alert('订单提交成功!感谢您的我们产品的信赖!');location.href='order.php';</script>";
}else{
echo "<script>alert('对不起,订单提交失败!请联系管理人员!');location.href='order.php';</script>";
}
}else{
echo "<script>alert('对不起,验证码错误');window.location='order.php';</script>";
}
}

//print_r($_SESSION['account']);
$qf->assign('orderlines', $_SESSION['orderlines']);
$qf->display('order.htm');
?>

解决方案 »

  1.   

    你要把出错的代码行指出来啊,你贴的代码中根本没有出现array_key_exists,应该是在public或checkuser文件中定义的某个函数中的。
      

  2.   

    不好意思,贴错了<?php
    include_once('public.inc.php');
    include_once('checkuser.php');

    $action = isset($_GET['action']) ? strtolower($_GET['action']) : '';
    $productClassId = $db->GetClassId(PRODUCTS);

    if ('add' == $action) {
    $cp_id = isset($_GET['cpid']) ? (int)$_GET['cpid'] : NULL;
    if ($cp_id) {
    if (array_key_exists($cp_id, $_SESSION['orderlines'])) {
    $_SESSION['orderlines'][$cp_id]['amount'] += 1;
    } else {
    $cp = $db->GetOne("SELECT * FROM #@__act WHERE PID IN($productClassId) AND #@__act.id='$cp_id'");
    if ($cp) {
    $_SESSION['orderlines'][$cp['id']] = array(
    'cp_id' => $cp['id'],
    'cpname' => $cp['title'],
    'cpimg' => $cp['img'],
    'price' => $cp['price'],
    'amount' => 1
    );
    }
    }
    }
    } else if ('del' == $action) {
    $cp_id = isset($_GET['cpid']) ? (int)$_GET['cpid'] : NULL;
    if ($cp_id && array_key_exists($cp_id, $_SESSION['orderlines'])) {
    unset($_SESSION['orderlines'][$cp_id]);
    }
    } else if ('empty' == $action) {
    $_SESSION['orderlines'] = array();
    }

    if ('POST' == $_SERVER['REQUEST_METHOD']) {
    if (is_array($_POST['amounts'])) {
    $_SESSION['orderlines'] = array();

    foreach ($_POST['amounts'] as $cp_id => $amount) {
    if (0 == $amount) continue;

    $cp = $db->GetOne("SELECT * FROM #@__act WHERE PID IN($productClassId) AND #@__act.id='$cp_id'");
    if ($cp) {
    $_SESSION['orderlines'][$cp['id']] = array(
    'cp_id' => $cp['id'],
    'cpname' => $cp['title'],
    'cpimg' => $cp['img'],
    'price' => $cp['price'],
    'amount' => $amount
    );
    }
    }
    }

    if ('ajaxupdate' == $action) {
    @header("content-Type: text/plain; charset=UTF-8");
    @header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    @header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    echo 'SUCCESS';
    exit();
    }

    if ('Checkout' == $_POST['submit']) {
    header("Location: order.php");
    } else {
    header("Location: shoppingCart.php");
    }
    exit();
    }

    $qf->assign('orderlines', $_SESSION['orderlines']);
    $qf->display('shoppingCart.htm');
    ?>
      

  3.   

    出错时,$_SESSION['orderlines'] 不是数组
      

  4.   


    虽然已经解决了,就是唠叨说的,$_SESSION['orderlines'] 不是数组。膜拜,唠叨大神果然不是盖得!!!