MySQL 替换我的 PHP 输入数据

MySQL replaces my PHP input data

所以,我一直在尝试使用 PHP 和 MySQL 创建一个 Signup/Login 进程。我创建了一个注册表单和一个处理页面。然后我就搞定了,设置邮箱为a@a.com,密码为MyPassword

然后我检查了数据库并感到惊讶。电子邮件输入正确,好的,但密码不正确!是我之前测试过的密码之一,比较有个性。

每次我再次尝试时,都会发生同样的事情。每当我注册时,密码总是更改为我的个人密码。

问题是,在我的代码中,我在任何地方都没有个人密码。我只用它来测试我的注册流程一次,现在它卡在了我的数据库中!

在这里,我使用测试凭据注册。密码是 asd 显然有 3 个字母长。

但是当我检查数据库时,我看到了以下内容。尽管我编辑了密码所以你看不到它,但它仍然很明显超过 3 个字母。

这是某种 MySQL 覆盖的东西吗,我还不知道?

这是注册页面的完整代码(可能有点长,请耐心等待):

<?php
session_start();
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['signUpemail'];
$password = $_POST['signUppassword'];
include("mysql_base.php");
echo "Preparing MYSQL Statement...<br>";
echo "<script>";
echo "firstPart()";
echo "function firstPart() {";
echo "document.write('Starting to process MYSQL Statement...')";
echo "window.setTimeout(secondPart(),2000)";
echo "}";
echo "function secondPart() {";
echo "document.write('Starting to stop processing MSYQL Statement...')";
echo "}";
echo "</script>";
echo "Started to proccess...<br>";
$sql = "INSERT INTO pages_accounts (email, pass, firstname, lastname, confirm) VALUES ('".$email."','".$password."','".$firstName."','".$lastName."','0')";
if ($conn->query($sql) === true){
  echo "<b>SIGNUP SUCCESS</b><br>";
  echo "SUCH HAPPINESS. WOW. MMM.<br><br>";
  echo "--Check your mail for a confirmation email. Check SPAM too!--";
  $headers = "MIME-Version: 1.0" . "\r\n";
  $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
  $headers .= 'From: FoxInFlame Pages<pages@foxinflame.tk>' . "\r\n";
  $message = "
  <html>
  <body>
  <center>
  <div style='background-color:orange'><h1>Confirm your Account</h1><br><h3>At FoxInFlame Pages</h3></div>
  You seem to have registered for an account at FoxInFlame Pages. Now please click on the following link to complete your registration, and start creating amazing websites!<br><a href='http://www.foxinflame.tk/pages/confirm.php?id=".$conn->insert_id."'>Click Here</a>
  </center>
  </body>
  </html>
  ";
  mail($email, "[CONFIRM] Account on FoxInFlame Pages", $message);
} else {
  echo "MUCH SADNESS. SUCH DEPRESSION. FAIL ERROR. NO RETURN.";
  echo "Error: ".$sql."<br>".$conn->error;
};
?>

在你的页面上我看到:

  <input style="color:white" type="password" name="password" required="" autocomplete="off">

所以你输入的名字是密码

但是在您的代码中您试图获取 signUppassword:

  $password = $_POST['signUppassword'];

你有什么地方有改造吗? javascript?

您的问题将在 include("mysql_base.php");。该文件将设置 $password 供其内部使用,这将覆盖您从 $_POST;

获得的 $password 变量

2 种解决方法:

1 - 先打开数据库连接。

<?php
session_start();
include("mysql_base.php");

$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['signUpemail'];
$password = $_POST['signUppassword'];

2 - 使用不同的变量名:

<?php
session_start();
include("mysql_base.php");

$signup_firstName = $_POST['firstName'];
$signup_lastName = $_POST['lastName'];
$signup_email = $_POST['signUpemail'];
$signup_password = $_POST['signUppassword'];

除此之外,注册页面上的密码字段没有 name="signUppassword",并且您没有 SQL 注入保护。