douxia2137 2013-05-23 12:28
浏览 27
已采纳

PHP脚本给出了意外的$ end [关闭]

I am getting a weird error in my login script. While through research i couldn't identify the problem. I am wondering if someone can help me thanks. This is the error message,

Parse error: syntax error, unexpected $end on line 43.

code:

<?php
    session_start();

    if(!isset($_SESSION["user_id"])){
        header("location:../../login.html");
    }


?>
<?php
    $username = $_POST['txt_username'];
    $password = $_POST['txt_password'];
    if ($username&&$password){

        $connect = mysql_connect("server", "username", "password") or die("No Server Found");

        mysql_select_db("databse") or die("No Connection");

        $query = mysql_query("SELECT * FROM account WHERE username='$username'");
        $numrows = mysql_num_rows($query); 

        if($numrows !=0){
            while ($rows = mysql_fetch_assoc($query)){

                $dbusername = $row['username'];
                $dbpassword = $row['password'];
            }
            if ($username == $dbusername && $password == dbpassword) {
                echo "Login Successful. <a href='homepage.html'>Click Here to go to the home page</a>";
                $_SESSION['username'] = $dbusername;
            } elseif ($username == '' || $password == '') {

                die("Please enter a username and password");

            } elseif (empty($dbusername)) {

                die("This account does not exsist");

            } else {
                die("Please enter a username and password");
            }
        }

?>
  • 写回答

3条回答 默认 最新

  • dongye3917 2013-05-23 12:30
    关注

    You need a closing brace on the last line, to close this if statement:

    if ($username&&$password){
    

    A decent IDE should have picked this up.

    You are missing $ on dbpassword line 28 & need to sanitize $username.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度