dpleylxzx47207117 2014-04-27 11:52
浏览 56
已采纳

将会话中的值输出到表单中

I am having some problem with trying to output 2 session values. It works fine when i output only the $_SESSION['mypassword']="myusername";

But then i try to output two session values, it does not work. Here is an example of what I have done so far.

<?php
session_start();


$_SESSION['mypassword']="myusername";
$_SESSION['studentid']="studentid";
echo "Logged in as".$_SESSION['studentid'];
echo "<h3 class='velkommen'>Logga inn som:<span class='spanclass'>" .$_SESSION['myusername']. "</span></h3>";

?>

The studentid output as studentid. The page before i did this:

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];
$studentid=$_POST['studentid'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$studentid = stripslashes($studentid);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$studentid = mysql_real_escape_string($studentid);
$sql="SELECT * FROM $tbl_name WHERE myusername='$myusername' AND password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;
$_SESSION['studentid'] = $studentid;
header("location:login_success.php" );

Any tip why it only the myusername who is correct? I need the both values to be in a form

<?php
    echo '<input type="hidden" name="myusername" value="'.$_SESSION['myusername'].'">';
?>

Any tip?

  • 写回答

2条回答 默认 最新

  • dqwh0109 2014-04-29 08:57
    关注

    Try this:

       <?php
        session_start();
        $_SESSION['mypassword']="myusername";
            $_SESSION['studentid']="studentid";
            echo "Logged in as".$_SESSION['studentid'];
            echo "<h3 class='velkommen'>Logga inn som:<span class='spanclass'>". $_SESSION['mypassword'] . "</span></h3>";
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答