dongyouji7022 2018-11-12 23:11
浏览 60

一个变量打印,其他我得到未定义的索引[重复]

I'm coding a webpage that has users register and then login. When trying to display the user's information on another page, I am struggling with trying to figure out why only the "username" variable will print but the "firstname" "lastname", "coursename" aren't appearing. Any insight would be helpful.

homepage.php - I am getting the error on the h3 User info tag

<?php
    session_start();
?>



<!DOCTYPE html>
<html>
<head>
    <title> Home Page</title>

    <link rel="stylesheet" href="css/allstyle.css" >

</head>
<body>

    <div class = "topnavbar">
        <ul>
            <li><a href = "UserInfo.php" class = "active"> User Info</a></li>
            <li><a href = "Homework.php"> Homework </a></li>
            <li><a href = "ToDoList.php"> To-Do-List </a></li>
            <li><a href = "WishList.php"> Wishlist </a></li>
            <li><a href = "MessageBoard.php"> MessageBoard </a></li>
        <ul>
    </div>


        <div id = "main-wrapper">
            <center>
                <h2>Home Page</h2>
                <h3> Welcome <?php echo $_SESSION['username']?> </h3>
                <h3> User Info: <?php echo $_SESSION['firstname']?> </h3>
                                <h3><?php echo $_SESSION['lastname']?></h3>
                <img src = "imgs/DefaultAvatar.jpg" class ="avatar"/>
            </center>


        <form class = "myform" action = "homepage.php" method = "post">

             <input name = "logout" type = "submit" id = "logout_btn" value = "Log Out"/><br></a>

        </form>

        <?php

            if(isset($_POST['logout']))
            {
                session_destroy();
                header('location: index.php');      
            }

        ?>

    </div>

</body>
</html>

register.php

<?php
    require 'dbconfig/config.php';

?>

<!DOCTYPE html>

<html>
<head>
    <title> Registration Page </title>

    <link rel="stylesheet" href="css/allstyle.css" >
</head>
<body>






<div id = "main-wrapper">
            <center>
                <h2>Registration Form</h2>
                <img src = "imgs/DefaultAvatar.jpg" class ="avatar"/>
            </center>


    <form class = "myform" action = "register.php" method = "post">


        <label><b>First Name:</b></label><br>
            <input name = "firstname" type = "text" class = "inputvalues" placeholder = "Enter your first name" required/><br>
        <label><b>Last Name:</b></label><br>
            <input name = "lastname" type = "text" class = "inputvalues" placeholder = "Enter your last name" required/><br>
        <label><b>Course Name:</b></label><br>
            <input name = "coursename" type = "text" class = "inputvalues" placeholder = "Enter your course name" required/><br>
        <label><b>Username:</b></label><br>
            <input name = "username" type = "text" class = "inputvalues" placeholder = "Enter your username" required/><br> 
        <label><b>Password:</b></label><br>
            <input name = "password" type = "password" class = "inputvalues" placeholder = "Enter your password" required/><br>
        <label><b> Confirm Password:</b></label><br>
            <input name = "cpassword" type = "password" class = "inputvalues" placeholder = "Confirm your password" required/><br>
        <input name = "submit_btn" type = "submit" id = "signup_btn" value = "Sign Up"/><br>
        <a href = "index.php"><input type ="button" id = "back_btn" value = " << Back to Login"/></a>

    </form>

</html>         


        <?php

            if(isset($_POST['submit_btn']))
            {
                    //echo '<script type  = "text/javascript"> alert("Sign up button clicked") </script>';


                    $firstname = $_POST['firstname'];
                    $lastname = $_POST['lastname'];
                    $coursename = $_POST['coursename'];

                    $username = $_POST['username'];
                    $password = $_POST['password'];
                    $cpassword = $_POST['cpassword'];


                if($password==$cpassword)
                {
                    $query= " select * from user WHERE username='$username'";
                    $query_run = mysqli_query($con, $query);


                    if(mysqli_num_rows($query_run)>0)
                    {
                        //Notifying user their username is taken
                        echo '<script type  = "text/javascript"> alert("This username is taken, please try another. ") </script>';
                    }
                    else
                    {
                        $query = "insert into user values ('$username','$password','$firstname','$lastname','$coursename')";
                        $query_run = mysqli_query($con,$query);

                        if($query_run)
                        {
                            echo '<script type  = "text/javascript"> alert("You have successfully registered! Return to login screen to login. ") </script>';

                        }
                        else
                        {
                            echo '<script type  = "text/javascript"> alert("Error!") </script>';

                        }

                    }

                }
                else
                {
                    echo '<script type  = "text/javascript"> alert("Your passwords do not match, please try again.") </script>';

                } 

        }

    ?>

</div>
</body>
</html>
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 一直显示正在等待HID—ISP