doumo2501 2016-01-29 02:08
浏览 41

回声没有传递var传递而

I am trying to get echo $userRow['student_firstname']; to pass into the html so I can use it as a automatic way to change displaying the users first name & logout with register & login. The first echo $userRow['student_firstname']; does work, however the second does not. The idea would be able to get the second to work, so I can remove the first. If there isn't a session then it displays the login & register.

    <?php
session_start();
include_once 'dbconnect_new.php';
?>

    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimal-ui">
        <link href="favicon.png" type="image/x-icon" rel="shortcut icon">
        <link href="assets/css/master.css" rel="stylesheet">
        <script src="assets/plugins/jquery/jquery-1.11.3.min.js"></script>
    </head>

    <?php if(isset($_SESSION['user'])) { 
    // error_reporting(E_ALL ^ E_DEPRECATED);
    $res=mysql_query("SELECT * FROM studentdata WHERE student_id=".$_SESSION['user']); 
    if ($res === FALSE){
        die(mysql_error());
    } 
    while($userRow=mysql_fetch_array($res))
    {
        echo $userRow['student_firstname'];
    }
    ?>
        <li class="dropdown">
            <a href="">
                <?php echo $userRow['student_firstname'];?><span class="nav-subtitle">Account</span></a</li>
                    <li><a href="includes/logout.php" title="">Logout<span class="nav-subtitle">Goodbye</span></a></li>
                    <?php } else { ?>
                        <li><a href="includes/register_new.php" title="">Register<span class="nav-subtitle">for Students</span></a></li>
                        <li><a href="includes/login_new.php" title="">Login<span class="nav-subtitle">for Students</span></a></li>
                        <?php  }  ?>

    </html>
  • 写回答

1条回答 默认 最新

  • dongshou9878 2016-01-29 03:28
    关注

    Check this link out http://php.net/manual/en/function.mysql-fetch-array.php, Tip: USE mysqli/pdo as mysql is deprecated.

    <?php
    session_start();
    include_once 'dbconnect_new.php';
    ?>
    
    <!DOCTYPE html>
    <html lang="en">
    
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimal-ui">
            <link href="favicon.png" type="image/x-icon" rel="shortcut icon">
            <link href="assets/css/master.css" rel="stylesheet">
            <script src="assets/plugins/jquery/jquery-1.11.3.min.js"></script>
        </head>
    
        <?php
        if (isset($_SESSION['user'])) {
            // error_reporting(E_ALL ^ E_DEPRECATED);
            $res = mysql_query("SELECT * FROM studentdata WHERE student_id=" . $_SESSION['user']);
            if ($res === FALSE) {//IF QUERY RETURNS NULL
                die(mysql_error());
            } else {
                $userRow = mysql_fetch_array($res, MYSQL_ASSOC); //DATA IN ARRAY TYPE
                //IF BELOW DOES NOT WORK USE print_r(); to check the structure of array !
                ?>
                <li class="dropdown">
                    <a href=""><?php echo $userRow['student_firstname']; //ACCESS DATA THROUGH ITS INDEX   ?><span class="nav-subtitle">Account</span></a>
                </li>
                <li>
                    <a href="includes/logout.php" title="">Logout<span class="nav-subtitle">Goodbye</span></a>
                </li>
                <?php
            }
        } else {
            ?>
            <li><a href = "includes/register_new.php" title = "">Register<span class = "nav-subtitle">for Students</span></a></li>
            <li><a href = "includes/login_new.php" title = "">Login<span class = "nav-subtitle">for Students</span></a></li>
            <?php } ?>
    </html>
    

    I Hope this works !

    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端