doufeixi6014 2011-12-01 03:41
浏览 15
已采纳

如何将$ _POST变量发布? [关闭]

This is my first page, which would be my login page. The user types in their username, hits login, and then the broswer should take them to login.php Index.html

<html>
<head>
<title>Login</title>
</head>
<body >

<br><br><br><br><h2 align=center>Quiz Taker</h2>
<br><br><br>
<p align=center></p>

<br>
    <form method="post" action="login.php">
        <table class="login" cellpadding=10 cellspacing=0 align="center" bgcolor="#cccccc" border="3">
        <tr>
            <td>
            <input type="radio" name="userType" value="Student"/> Student
            <input type="radio" name="userType" value="Teacher"/> Teacher
             <td>
             Username:</td><td><input type="text" name="username" size=10>
             </td>
        </tr>
        <tr>
             <td colspan=2 align="center">
             <input type="submit" name="submit" value="  Log In  ">
             </td>
        </tr>
    </table>
    </form>


</body>
</html>

When the user hits submit it will go to login.php which looks like this:

<?php

include_once("DatabaseConnection.php");

$stmt=$DBH->prepare("SELECT * FROM QuizUser where Name=?")
$stmt->bindValue(1, $_POST['username']);
$stmt->execute();
if ($row=$stmt->fetch())
    {
        $ID=$row['ID'];
    }
    else
    {

        $stmt=$DBH->prepare("INSERT INTO QuizUser(Name) VALUES(?)")
        $stmt->bindValue(1, $_POST['username']);
        $stmt->execute();
        $ID=$DBH->lastInsertId();
    }
    $_SESSION['userID']= $ID;
    $_SESSION['userName']= $_POST['username'];
    $_SESSION['userType']=$_POST['userType'];

    if($_POST['userType'] == "Student")
    {
        header($string["Location:student.php"]);
    }
    else 
    {
        header($string["Location:teacher.php"]);    
    }

    ?>

Which is not working and I cannot figure out why. It just pops up a parse error: syntax error, unexpected T_VARIABLE in ....myfile.... at line whever the first time I try and use the $_POST variable. By the way, I am starting my session in the DataBaseConnection.php that is imported at the top of login.php.

  • 写回答

3条回答 默认 最新

  • duanbohan2015 2011-12-01 04:09
    关注

    Your header functions are written incorrectly.

    header($string["Location:student.php"]);
    

    should be

    header("Location: student.php");
    

    Likewise,

    header($string["Location:teacher.php"]);
    

    should be

    header("Location: teacher.php");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab