繁体   English   中英

如何在会话ID中获取值

[英]how to take a value in Session id

我的代码在第13行, starttimer.php?testid=$row[0] ,我想在会话testid分配$row[0]的值。 帮助我做到这一点。(数据库表是rec_test ,列是pid

<?php
extract($_GET);
$rs=mysql_query("select * from rec_test");
if(mysql_num_rows($rs)<1)
{
echo "<br><br><h2 class=head1> No Quiz available </h2>";
exit;
}
echo "<h2 class=head1> Select Quiz Name to Give Quiz </h2>";
echo "<table align=center>";
while($row=mysql_fetch_row($rs))
{
echo "<tr><td align=center ><a href=starttimer.php?testid=$row[0]<h3><font color=red>$row[1]</font></h3></a></td></tr>";
echo "<tr><td> &nbsp;</td></tr>";
}
echo "</table>";
?>

我不知道我是否完全理解您的问题,但是我想您想将pid列分配给链接。

首先要做的是在查询数据库时不要使用通用的“ * ”,其次要使用mysql_fetch_assoc取回关联数组。

<?php
extract($_GET);
$rs = mysql_query("SELECT pid, name FROM rec_test");
if ( mysql_num_rows($rs) < 1 )
{
    echo "<br><br><h2 class=head1> No Quiz available </h2>";
    exit;
}
echo "<h2 class=head1> Select Quiz Name to Give Quiz </h2>";
echo "<table align=center>";
while ($row = mysql_fetch_assoc($rs))
{
    echo '<tr>'
        .'<td align="center" >'
         .'<a href="starttimer.php?testid='.$row['pid'].'">'
          .'<h3><font color="red">'.$row['name'].'</font></h3>'
         .'</a>'
        .'</td>'
        .'</tr>';
    echo "<tr><td> &nbsp;</td></tr>";
}
echo "</table>";

还应考虑切换到Mysqli或PDO,因为从PHP 5.5开始, mysql扩展已被取消并全部删除。

并且请不要对非安全数据使用提取,因为PHP手册指出:警告

不要对用户输入(如$ _GET,$ _ FILES等)等不可信数据使用extract()。 如果这样做,例如,如果您想暂时运行依赖于register_globals的旧代码,请确保使用非覆盖标志值之一(例如EXTR_SKIP),并且要注意,提取时应使用在variables_order中定义的相同顺序php.ini。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM