Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 创建登录脚本时遇到问题_Php_Mysql - Fatal编程技术网

Php 创建登录脚本时遇到问题

Php 创建登录脚本时遇到问题,php,mysql,Php,Mysql,获取此错误时,您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以获取第1行“”附近要使用的正确语法 从这里得到上述错误,我是PHP新手,所以我不知道问题可能是什么,有什么帮助吗 <?php session_start(); //ob_start(); //make connection $con = mysql_connect ("***" , "***", "***") or die ("Query died: connect"); mysql_selec

获取此错误时,您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以获取第1行“”附近要使用的正确语法

从这里得到上述错误,我是PHP新手,所以我不知道问题可能是什么,有什么帮助吗

<?php
 session_start();
 //ob_start();


//make connection
$con = mysql_connect ("***" , "***", "***")
    or die ("Query died: connect");

mysql_select_db("*****",$con);

// Grab User submitted information
$user = $_POST["myuser"];
$pass = $_POST["mypwd"];

strong text$result = mysql_query("SELECT FirstName, Password FROM memberst WHERE FirstName   =      $user");
if (!$result) { // add this check.
die('Invalid query: ' . mysql_error());
}
$row = mysql_fetch_array($result);

if($row["Firstname"]==$user && $row["Password"]==$pass) {
echo $row["Firstname"];
  //header("location:LoginSuccess.php");
 }

 else {
 echo"Sorry, your credentials are not valid, Please try again.";
    }`enter code here`

?>

试试这个

<?php
    define('DB_host', 'localhost');

    define('DB_username', 'root');

    define('DB_password','');


     if( !(isset( $_POST['login'] ) ) ) { ?>
    <div align="center">
    <fieldset style="width:10%;">

    <form name="login" action="" method="POST">
        <div align="left">
        <label  for "username">Username: </label>
        <input type="text" name="username"/>
     <br /> 
        <label for "password">Password: </label>
        <input type="password" name="password"/><br />
     </div>
     <div align="center">
     <input type="submit" name="login" value="Login" />
     <input type="reset"  value="Reset" />
             </div>
        </form>
    </fieldset>
        </div>
    </div> 

    <?php 
    } else {
    $con = new PDO("mysql:host=". DB_host .";dbname=YOUR DATABASE NAME", DB_username , DB_password);

    $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

    $sql = "SELECT * FROM users WHERE username = :username AND password = :password LIMIT 1";


    $stmt = $con->prepare( $sql );

    $stmt->bindValue( "username", $_POST['username'], PDO::PARAM_STR );
    $stmt->bindValue( "password",  $_POST['password'] , PDO::PARAM_STR );
    $stmt->execute();




    if( $stmt->rowCount() > 0 ) {


    header('location: home.php');


    } else {
      echo '<script> window.alert("Incorrect Input")
        window.location.href="login.php";</script>';
           }
    }
    ?>

用户名:

密码:

在这方面有很多危险的做法,我会找到一个更好的方法。这不太顺利。本教程可能是从2001年开始的……使用此脚本,您将丢失整个服务器:虽然没有那么复杂,但我建议PDO,检查一下。危险:您正在使用,并且应该使用。您也很容易受到现代API的影响,因为它会使您更容易使用。