duandi8838 2014-03-18 23:10
浏览 15
已采纳

会话ID更改保存到DB

I have this small problem on Session. Ill show you the codes below.

//checking session orderid if not created  
$setSession = $_SESSION['neworderid'];
if (empty($setSession)) {
    $neworderid = mt_rand(1000000000, 9999999999);  
    $_SESSION['neworderid'] = $neworderid;
}

//check if order_id exists in the database  
$db->setQuery("SELECT * FROM mn_orderitems WHERE order_id =" . $_SESSION['neworderid']);  
$query = $db->loadResult();  
if (!empty($query)) {  
    //if exists, do nothing  
    echo 'Not Empty';  
} else {
    //if order id doesn't exist, save the new order item  
    $qry = "INSERT INTO mn_orderitems (order_id, product_id, orderitem_name, orderitem_quantity, orderitem_price, orderitem_final_price) VALUES
        ('" . $_SESSION['neworderid'] . "', '" . $item->product_id . "', '" . $item->orderitem_name . "', '" . $item->orderitem_quantity . "', '" . $item->orderitem_price . "', '" . $item->orderitem_final_price . "')";  
    $result = mysql_query($qry);  
    if (!$result) {  
        echo "Error";  
    } else {  
        echo "Saved";  
    }  
    echo 'Empty';  
}  

Problem:
"When I try to echo the $_SESSION['neworderid']; it outputs = 8152269414
But when it is being save to database the order_id changes to 2147483647".

This only happens in live server. No problem in my localhost Apache.

  • 写回答

2条回答 默认 最新

  • duan01203 2014-03-18 23:17
    关注

    The problem you are having is not with the PHP script itself, but your database structure. In MySQL the biggest number you can store (declared as INT) is 2147483647. If you want to store bigger numbers, you'll have to either change the script to generate a lower number OR change the DB to use BIGINT.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)