html type id,html - PHP - input type hidden to get id - Stack Overflow

The problem is you are creating multiple with name='SID' and the receiving page will probably only accept the first one. You need to create them as an array instead with []

echo " ";

//----------------------------------^^^^^^

In the receiving page, check the contents with var_dump($_POST['SID']). It will be an array and you can iterate it with a foreach().

I note that you are nesting inside s. That is probably not a good approach ( I don't think it is valid HTML). Instead, store all the SID in an array and loop twice to create your inputs.

$ids = array();

while( $row = mysql_fetch_array($result)) {

// First make an array of ids

$ids[] = $row;

}

Then loop over it twice, to build the select options, and the hidden inputs:

// opened above...

// Inside the tag already opened...

foreach ($ids as $id) {

echo "$id[Sname] ";

}

// Close the

//

// Then later, loop to build the hidden inputs in the array format

foreach ($ids as $id) {

echo " ";

}

On the subject of valid HTML... I also see a stray closing in there. is deprecated, and instead you should be using CSS to define font properties.

Update after comments:

If you want to pass the SID along with the value (Sname) in the then it is easiest to skip the hidden entirely. Instead, pass both values in the attribute, separated by something like a |. In the PHP code that receives it, explode() them back into two values:

// In your original while loop:

// The value consists of both SID and Sname, separated by |

// Now, you have no need for the at all. Remove them.

echo "$row[Sname] ";

// Then in the PHP script which receives the form values, explode() them:

// Both values come from the

list($SID, $Sname) = explode("|", $_POST['Sname']);

// Now your variables $SID and $Sname hold the correct values

// If you need to reuse them, store into `$_SESSION

session_start();

$_SESSION['SID'] = $SID;

$_SESSION['Sname'] = $Sname;

// On other scripts, to read the values

session_start();

echo $_SESSION['SID'];

If you are unfamiliar with how to use $_SESSION, review the manual on basic usage. Long story short, you must call session_start() on each script that accesses $_SESSION, and you must do so before the script produces any output, including whitespace. This is the standard method of sharing data between scripts.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值