简体   繁体   English

HTML格式无法在Firefox

[英]html form not working in firefox

I have just started learning PHP and I cant seem to to work like this is not going to welcome.php please help? 我刚刚开始学习PHP,但是我似乎无法正常工作,因为这将welcome.php请帮忙吗? Thankyou for your help as I have litterally put my head into this :( 谢谢您的帮助,因为我对此表示怀疑:(

$user=$_POST['user'];
$pass=$_POST['pass'];


$que ="SELECT * FROM users WHERE username='$user' and password='$pass'";
$res=mysql_query($que);

    $c=mysql_num_rows($res);

    if($c==1){
    $_SESSION['user'] = $user; 
    header("location: welcome.php");
    }
    else {
    header("location: empty.php");
    }
    ?>




        <form name="myform" method="POST" action="login.php">


         <input name="username" type="text" id="username">

         <input name="pass" input type="password" id="pass">

         <input type="submit" name="Submit" value="Login">

        </form>

Try this please: 请尝试以下方法:

      <?php
    session_start(); // You need this if you use a session    
        $user = mysql_escape_string($_POST['user']); // Defend from SQL Injection
            $pass = mysql_escape_string($_POST['pass']);

            if(isset($_POST['Submit']))
{
            $que = "SELECT * FROM users WHERE username='$user' and password='$pass';";
            $res = mysql_query($que);

                $c = mysql_num_rows($res);

                if($c==1){ // if you want use a session you need add session_start();
                $_SESSION['user'] = $user; 
                header("location: welcome.php");
                }
                else {
                header("location: empty.php");
                }
}
                ?>




                    <form name="myform" method="POST" action="login.php">


                     <input name="username" type="text" id="username">

                     <input name="pass" type="password" id="pass">

                     <input type="submit" name="Submit" value="Login">

                    </form>

If you have properly used session_start(); 如果您正确使用了session_start(); It has already been mentioned where you have messed up, I will however post it for you so you can copy/paste and see it for yourself :) Furthermore, Beware of SQL Injection/XSS Study PDO/msqli 已经提到了您搞砸的地方,但是我会为您发布,以便您可以复制/粘贴并亲自查看:)此外,请注意SQL Injection/XSS Study PDO/msqli

    <?php 
        session_start();
if(isset($_POST['Submit']){
        $user=$_POST['user'];
        $pass=$_POST['pass'];


        $que ="SELECT * FROM users WHERE username='$user' and password='$pass'";
        $res=mysql_query($que);

            $c=mysql_num_rows($res);

            if($c==1){
            $_SESSION['user'] = $user; 
            header("location: welcome.php");
            }
            else {
            header("location: empty.php");
            }

    }
    ?>

            <form name="myform" method="POST" action="login.php">


             <input name="user" type="text">

             <input name="pass" input type="password">

             <input type="submit" name="Submit" value="Login">

            </form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM