1

我一直在与 phpMyAdmin insert 斗争一段时间,它没有给我一个错误,但它不会插入到数据库中。

我的代码是这样的

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="43%" id="AutoNumber1">
  <tr>
    <td width="100%">
    <p align="left">&nbsp;</td>
  </tr>
  <tr>
    <td width="100%">
    <form method="GET" name="testform" id="testform" action="logout.php">
      <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="69%" id="AutoNumber2" height="63">
        <tr>
          <td width="36%" height="22">Username</td>
          <td width="64%" height="22"><input type="text" name="user" size="20"></td>
        </tr>
        <tr>
          <td width="36%" height="22">password</td>
          <td width="64%" height="22">
          <input type="password" name="passwd" size="20"></td>
        </tr>
        <tr>
          <td width="36%" height="19">&nbsp;</td>
          <td width="64%" height="19">
          <input type="submit" value="login" name="login"></td>
        </tr>
      </table>
    </form>
    </td>
  </tr>
</table>

</body>

</html>

现在php也是这样的

<?php

require_once('inc/config.php');
$user = $_GET['user'];
$pass = $_GET['passwd'];

//database connection
$conn = mysqli_connect(DBHOST,DBUSER,DBPASS,DB);

//mysql anti injection    
$username = mysql_real_escape_string($_GET['user']);
$password = mysql_real_escape_string($_GET['passwd']);

$sql = "INSERT INTO people (`username`, `password`) VALUES ('$username', '$password');";
mysqli_close($conn);

echo "Inserted";

?>

问题是,在本地主机上查看时,我看不到我插入 mysql 数据库的内容;问题是什么?

4

1 回答 1

-2

似乎问题可能是使用';' 在以下行的末尾两次:

$sql = "INSERT INTO people ( username, password) VALUES ('$username', '$password');";

试试下面的。

$sql = "INSERT INTO people ( username, password) VALUES ('$username', '$password');"

于 2021-03-25T17:42:14.707 回答