我正在使用基于CodeIgniter构建的这个头像社区引擎,除商店系统外,一切正常。
每当我尝试购买物品时,我都会得到这个:
遇到错误
shop_item_id必须有效
我已将问题缩小到这段代码:
public function purchase_item()
{
$shop_item_id = $this->input->post('item_id');
if(!is_numeric($shop_item_id)) show_error('shop_item_id must be valid');
$shop_item_query = $this->db->join('avatar_items', 'avatar_items.item_id = shop_items.item_id')->get_where('shop_items', array('shop_item_id' => $shop_item_id));
if($shop_item_query->num_rows() > 0):
$shop_item_data = $shop_item_query->row_array();
else:
show_error('shop_item could not be found.');
endif;
$shop_id = $shop_item_data['shop_id'];
if ( ! $shop_data = $this->cache->get('shop_data_'.$shop_id)):
$shop_data = $this->db->get_where('shops', array('shop_id' => $shop_id))->row_array();
$this->cache->save('shop_data_'.$shop_id, $shop_data, 2400);
endif;
解决方案是什么?
p.s:我正在使用crysandrea(https://github.com/tylerdiaz/Crysandrea)的脚本。我的任务需要这个。
以下是代码:
<form action="/shops/purchase_item/" method="POST">
<input type="hidden" name="item_id" value="<?php echo $item_data['shop_item_id'] ?>" />
<button type="submit" class="main_button">Purchase item</button>
</form>
答案 0 :(得分:0)
<form action="/shops/purchase_item/" method="POST">
<input type="hidden" name="item_id" value="<?php echo $item_data['shop_item_id']; ?>" />
<button type="submit" class="main_button">Purchase item</button>
</form>
答案 1 :(得分:0)
您应该在函数
中编写此代码 if(!is_numeric((int)$shop_item_id)) show_error('shop_item_id must be valid');