通过php(Mysqli)INSERT无法进入MySQL

时间:2016-01-03 00:51:45

标签: php mysql mysqli

我通过php(5.6.10)创建了Sigh Up程序& MySQL的(42年5月5日)。 但是INSERT错误发生在MySQL上。 我想告诉我为什么会收到错误。

叹气程序是
regist.php→按用户获取名称 ↓
check.php→用户名确认。

complete.php→插入MySQL。
数据库名称=测试 表名=人。

regist.php

<?php
session_start();
if(!empty($_POST)){
 if($_POST['name'] == ''){
 $error['name'] = 'blank';
 }
if(empty($error)){
$_SESSION = $_POST;
  }
 }
?>

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <title>Sigh Up</title>
</head>
<body>
  <p>Input</p>
  <form action="check.php" method="post" enctype="multipart/form-data">
  <dl>
    <dt>Name<font color="red"> *</font></dt>
      <dd>
      <input type="text" name="name" size="35" maxlength="255"
        value="<?php echo htmlspecialchars($_POST['name'], ENT_QUOTES, 'UTF-8')
        ?>">
      <?php if($error['name'] Input Username</font></p>
      <?php endif; ?>

      </dd>
</dl>
  <div><input type="submit" value="OK"></div>
  </form>
</body>
</html>

check.php

<?php
session_start();
$_SESSION = $_POST;
echo 'Name:'.$_SESSION['name'];
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Sigh Up</title>
</head>
<body>
<form action="complete.php" method="post">
<dl>
</dl>
<div><a href="regist.php?action=rewrite">&laquo;&nbsp;Rewrite</a>
<input type="submit" value="Register"></div>
</form>
</body>
</html>

complete.php

<?php
session_start();
require('/Applications/MAMP/htdocs/test/db_connect.php');
if(!$db_connect){
  die('Miss');
}echo 'Success<br />';

$name = $_SESSION['name'];
echo $name.'<br />';

$query = "INSERT INTO human (name)". "VALUES ($name)";
//database_regist
$result = mysqli_query($db_connect,$query)
or die('error');
mysqli_close($db_connect);
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Sigh Up</title>
</head>
<body>
  <p>Complete</p>
  <p><a href="../">Log in</a></p>
</body>
</html>

db_connect.php

<?php
    $db_connect = mysqli_connect('localhost', 'root', 'root', 'test') or die(mysqli_connect_error());
    mysqli_set_charset($db_connect, 'utf8');
?>

0 个答案:

没有答案