本文介绍了在添加@mysql_real_escape_string时获取空白表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi

I have a login form, when i tried to login i got this two errors:
Notice: Undefined index: username in C:\wamp64\www\FormTutorial\php\luana_login.php on line 6
Notice: Undefined index: password in C:\wamp64\www\FormTutorial\php\luana_login.php on line 7

I have been busting my head to figure out how to solve it so I went online to see if I can find a solution to fix the errors and I came across. I dont know how effective it is so
I have decide to give a tried to see how it work but this things when i put in my codes the errors gone but it give me a blank page when it should have give me the login form
to which i should be able to login.

this is the codes that I tried to use:




$username = @mysql_real_escape_string($_POST['user_name']);//when i add the code the errors is gone but give me a blank
$password = @mysql_real_escape_string($_POST['password']);





我尝试了什么:





What I have tried:

<pre>this is my codes below for the login form
<?php
        // capture values from the form and store in php variables
        $uname=($_POST['username']);
        $pword=($_POST['password']);
        //connection to the database
        $db_host='localhost';
        $db_username='root';
        $db_password="";
        $con=mysqli_connect($db_host, $db_username, $db_password) or die (mysqli_connect_error());
        //select the database to query
        mysqli_select_db($con, 'staff') or die (mysqli_error($con));
        $sql="SELECT * FROM applicant  WHERE uname ='$uname' AND pword=md5('$pword')";
        $result=mysqli_query($con,$sql) or die ("Error:" .mysqli_error($con));
        $rowcount=mysqli_num_rows($result);
        if($rowcount == 1)
        {
            session_start();
            $_SESSION['user']=$username;
            header("location:luana_profile.php");
        }
        else
        {
            echo"<script type=\"text/javascript\">
            alert('username and password doesn't exist');
            window.location\"../xhtml/luana_login.html\";
            </script>";



}


}

mysqli_close($con);

推荐答案




这篇关于在添加@mysql_real_escape_string时获取空白表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:45