请教编程问题:加了参数以后,程序不再正常运行

adbtob 2009-12-15 12:17:41
加参数前,程序正常运行:
原来lib_insert.php的插入历史函数没有加入参数,
function insert_history()//lib_insert.php
{
$str = '';
if (!empty($_COOKIE['ECS']['history']))
{
$where = db_create_in($_COOKIE['ECS']['history'], 'goods_id');
$sql = 'SELECT goods_id, goods_name, goods_thumb, shop_price FROM ' . $GLOBALS['ecs']->table('goods') .
" WHERE $where AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0";
$query = $GLOBALS['db']->query($sql);
$res = array();
while ($row = $GLOBALS['db']->fetch_array($query))
{
$goods['goods_id'] = $row['goods_id'];
$goods['goods_name'] = $row['goods_name'];
$goods['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods['shop_price'] = price_format($row['shop_price']);
$goods['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
$str.='<ul class="clearfix"><li class="goodsimg"><a href="'.$goods['url'].'" target="_blank"><img src="'.$goods['goods_thumb'].'" alt="'.$goods['goods_name'].'" class="B_blue" /></a></li><li><a href="'.$goods['url'].'" target="_blank" title="'.$goods['goods_name'].'">'.$goods['short_name'].'</a><br />'.$GLOBALS['_LANG']['shop_price'].'<font class="f1">'.$goods['shop_price'].'</font><br /></li></ul>';
}
$str .= '<ul id="clear_history"><a onclick="clear_history()">' . $GLOBALS['_LANG']['clear_history'] . '</a></ul>';
}
return $str;
}
在common.js中的addToCart函数可以通过ajax.call到flow.php
function addToCart(goodsId, parentId)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formBuy = document.forms['ECS_FORMBUY'];

// 检查是否有商品规格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);

if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}
}

goods.spec = spec_arr;
goods.goods_id = goodsId;
goods.number = number;
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);

Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), addToCartResponse, 'POST', 'JSON');
}

但是在lib_insert.php中加入参数之后
function insert_history($arr)
{
$str = '';
if (!empty($_COOKIE['ECS']['history']))
{
$where = db_create_in($_COOKIE['ECS']['history'], 'goods_id');
$sql = 'SELECT goods_id, goods_name, goods_thumb, shop_price FROM ' . $GLOBALS['ecs']->table('goods') .
" WHERE $where AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0";
$query = $GLOBALS['db']->query($sql);
$res = array();
while ($row = $GLOBALS['db']->fetch_array($query))
{
//print_r ($GLOBALS['db']->fetch_array($query));
$goods['goods_id'] = $row['goods_id'];
$goods['goods_name'] = $row['goods_name'];
$goods['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods['shop_price'] = price_format($row['shop_price']);
$goods['url'] = build_uri('goods', array('gid'=>$row['goods_id'], 'aaa'=>$arr['aaa'], 'bbb'=>$arr['bbb'], 'ccc'=>$arr['ccc']), $row['goods_name']);//'aaa'=>$arr['aaa'], 'bbb'=>$arr['bbb'], 'ccc'=>$arr['ccc']是新加入的参数
$str.='<ul class="clearfix"><li class="goodsimg"><a href="'.$goods['url'].'" target="_blank"><img src="'.$goods['goods_thumb'].'" alt="'.$goods['goods_name'].'" class="B_blue" /></a></li><li><a href="'.$goods['url'].'" target="_blank" title="'.$goods['goods_name'].'">'.$goods['short_name'].'</a><br />'.$GLOBALS['_LANG']['shop_price'].'<font class="f1">'.$goods['shop_price'].'</font><br /></li></ul>';
}
$str .= '<ul id="clear_history"><a onclick="clear_history()">' . $GLOBALS['_LANG']['clear_history'] . '</a></ul>';
}
return $str;
}
加入的参数是$arr,从模版中获得的参数是'aaa'=>$arr['aaa'], 'bbb'=>$arr['bbb'], 'ccc'=>$arr['ccc'],

加了参数以后,出现问题:
---------------------------------------------------------------------------
在加入参数之后,addToCart在Ajax.call后无法跳转的flow.php
错误在:
case "JSON" :
result = this.preFilter(xhr.responseText);
try
{
result = result.parseJSON();
}
catch (ex)
{
throw this.filename + "/parseResult() error: can't parse to JSON.\n\n" + xhr.responseText;//程序运行到这里无法继续运行
}
break;
在insert_history中不加参数addToCart就可以跳转到flow.php,但是加入参数之后就无法跳转到flow.php
...全文
122 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
骄傲青蛙 2009-12-21
  • 打赏
  • 举报
回复
有报错吗, 不正常在那里 ? 那方面 ?
USEKJAVA 2009-12-21
  • 打赏
  • 举报
回复
function insert_history($arr)
{
$str = '';
if (!empty($_COOKIE['ECS']['history']))
{
$where = db_create_in($_COOKIE['ECS']['history'], 'goods_id');
$sql = 'SELECT goods_id, goods_name, goods_thumb, shop_price FROM ' . $GLOBALS['ecs']->table('goods') .
" WHERE $where AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0";
$query = $GLOBALS['db']->query($sql);
$res = array();
while ($row = $GLOBALS['db']->fetch_array($query))
问题出在这里,原因自己分析。
{
//print_r ($GLOBALS['db']->fetch_array($query));
$goods['goods_id'] = $row['goods_id'];
$goods['goods_name'] = $row['goods_name'];
$goods['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods['shop_price'] = price_format($row['shop_price']);
$goods['url'] = build_uri('goods', array('gid'=>$row['goods_id'], 'aaa'=>$arr['aaa'], 'bbb'=>$arr['bbb'], 'ccc'=>$arr['ccc']), $row['goods_name']);//'aaa'=>$arr['aaa'], 'bbb'=>$arr['bbb'], 'ccc'=>$arr['ccc']是新加入的参数
$str.=' <ul class="clearfix"> <li class="goodsimg"> <a href="'.$goods['url'].'" target="_blank"> <img src="'.$goods['goods_thumb'].'" alt="'.$goods['goods_name'].'" class="B_blue" /> </a> </li> <li> <a href="'.$goods['url'].'" target="_blank" title="'.$goods['goods_name'].'">'.$goods['short_name'].' </a> <br />'.$GLOBALS['_LANG']['shop_price'].' <font class="f1">'.$goods['shop_price'].' </font> <br /> </li> </ul>';
}
$str .= ' <ul id="clear_history"> <a onclick="clear_history()">' . $GLOBALS['_LANG']['clear_history'] . ' </a> </ul>';
}
return $str;
}
adbtob 2009-12-15
  • 打赏
  • 举报
回复
参数中应该没有中文的
jaxio 2009-12-15
  • 打赏
  • 举报
回复
参数中是否有中文,如果是 urlencode 传过去看看

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧