为了账号安全,请及时绑定邮箱和手机立即绑定

如何通过表单连接php代码?

如何通过表单连接php代码?

PHP
饮歌长啸 2022-12-23 16:06:02
所以我第一次做了一个单独的登录页面,也是第一次使用 PHP 代码。如您所见,下面是我的表单代码。<form method="post" action="validate_login.php"><div class="login-inhoud">    <h1>Login</h1>    <div class="login-input">        <input type="email" id="users_email" name="users_email" size="30" maxlength="30" placeholder="Email">        <br><br>        <input type="password" id="users_pass" name="users_pass" size="30" maxlength="30"               placeholder="Wachtwoord">    </div>    <br>    <div class="login-submit">        <button type="submit"><b>submit</b></button>    </div></div>但是,当我添加此 Php 代码时,它不起作用。另外 mysql_connect 和 mysqli_connect 之间有什么区别?    <?php// Grab User submitted information$email = $_POST["users_email"];$pass = $_POST["users_pass"];// Connect to the database$con = mysqli_connect("localhost", "root", "");// Make sure we connected successfullyif ($con->connect_errno) {    echo "Failed to connect to MySQL: " . $con->connect_error;    exit(); }// Select the database to use    mysqli_select_db("my_dbname", $con);    $result = mysqli_query("SELECT users_email, users_pass FROM users WHERE users_email = $email");    $row = mysqli_fetch_array($result);    if ($row["users_email"] == $email && $row["users_pass"] == $pass)        echo "You are a validated user.";    else        echo "Sorry, your credentials are not valid, Please try again.";    ?>
查看完整描述

1 回答

?
慕雪6442864

TA贡献1812条经验 获得超5个赞

你的代码中有很多错误......


试试这个,希望它有效:


    <?php

// Grab User submitted information

$email = $_POST["users_email"];

$pass = $_POST["users_pass"];


// Connect to the database

$con = mysqli_connect("localhost", "root", "", "my_dbname"); //Why complicate life?!

// Make sure we connected successfully

if (mysqli_connect_errno()) {

    echo "Failed to connect to MySQL: " . mysqli_connect_error();

    exit;

}


$result = mysqli_query($con, "SELECT users_email, users_pass FROM users WHERE users_email = $email");


    $row = mysqli_fetch_array($result);


    if ($row["users_email"] == $email && $row["users_pass"] == $pass)

        echo "You are a validated user.";

    else

        echo "Sorry, your credentials are not valid, Please try again.";

    ?>


查看完整回答
反对 回复 2022-12-23
  • 1 回答
  • 0 关注
  • 88 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信