2

嘿伙计们,这是我正在使用的代码

$ch="s1";
$_SESSION[$ch] = array();
$_SESSION[$ch][] = $_POST['t0'];
$_SESSION[$ch][] = $_POST['t1'];
$_SESSION[$ch][] = $_POST['t2'];
$_SESSION[$ch][] = $_POST['t3'];
$_SESSION[$ch][] = $_POST['t4'];
$_SESSION[$ch][] = $_POST['t5'];
$_SESSION[$ch][] = $_POST['t6'];

但是当我在屏幕上打印会话数据时$_SESSION['s1'][0],所有其他索引的所有数据$_SESSION['s1'][1]$_SESSION['s1'][6]没有显示。

这是结果var_dump($_SESSION)

's1' => array (size=7) 
   0 => string 'All Purpose Horn Anvil A-1t1=Shipping Weight: 900gmst2=Price: € 5.00t3=Quantity: t4= t5=56t6=All Purpose Horn Anvil A-1 Shipping Weight: 900gms Price: € 5.00 Quantity: 56' (length=192) 
    1 => null 
    2 => null 
    3 => null 
    4 => null 
    5 => null 
    6 => null

出于某种原因,POST 索引(即 t0 到 t6)显示在 s1 中。

4

4 回答 4

1

可能您在其他地方覆盖了该数据,或者只是在打印时出错。

$ch="s1";
$_SESSION[$ch] = array();
$_SESSION[$ch][] = mt_rand(1,200);
$_SESSION[$ch][] = mt_rand(1,200);
$_SESSION[$ch][] = mt_rand(1,200);
$_SESSION[$ch][] = mt_rand(1,200);
$_SESSION[$ch][] = mt_rand(1,200);
$_SESSION[$ch][] = mt_rand(1,200);
$_SESSION[$ch][] = mt_rand(1,200);
print_r( $_SESSION );

输出:

数组 ( [s1] => 数组 ( [0] => 158 [1] => 145 [2] => 110 [3] => 139 [4] => 153 [5] => 183 [6] => 51))

于 2013-10-08T14:01:22.090 回答
1

将数据传递给 POST 是一个错误。在 Jquery 中,我使用这个变量之间没有“&”,这是导致问题的原因。

var dataString = 't0=' + txt[0]+ '&t1='+ txt[1] + '&t2='+ txt[2] + '&t3='+ txt[3] + '&t4='+ txt[4] + '&t5='+ txt[5] + '&t6='+ temp;
于 2013-10-08T14:32:25.483 回答
0

尝试在相等之前添加一个点:

    $ch="s1";
    $_SESSION[$ch] = array();

    $_SESSION[$ch][] .= $_POST['t0'];
    $_SESSION[$ch][] .= $_POST['t1'];
    $_SESSION[$ch][] .= $_POST['t2'];
    $_SESSION[$ch][] .= $_POST['t3'];
    $_SESSION[$ch][] .= $_POST['t4'];
    $_SESSION[$ch][] .= $_POST['t5'];
    $_SESSION[$ch][] .= $_POST['t6'];

您可以在此链接 ( 3v4l.org/8ZDi9 )上看到此代码:

<?php

    $ch="s1";
    $_SESSION[$ch] = array();

    $_SESSION[$ch][] .= 11;
    $_SESSION[$ch][] .= 22;

    var_dump($_SESSION);
于 2013-10-08T14:02:25.283 回答
0
$ch="s1";
$_SESSION[$ch] = array();
$_SESSION[$ch][0] = $_POST['t0'];
$_SESSION[$ch][1] = $_POST['t1'];
$_SESSION[$ch][2] = $_POST['t2'];
$_SESSION[$ch][3] = $_POST['t3'];
$_SESSION[$ch][4] = $_POST['t4'];
$_SESSION[$ch][6] = $_POST['t5'];
$_SESSION[$ch][7] = $_POST['t6'];

或更好

$ch="s1";
$_SESSION[$ch] = array();


for ($i=0; $i<=6; $i++)
{
   $_SESSION[$ch][$i] = $_POST['t'.$i];
}
于 2013-10-08T14:37:42.683 回答