为什么我不能将数据插入数据库

时间:2018-07-15 04:37:14

标签: php html css database

<?php

session_start();
$host = "localhost";
$user = "root";
$password = "";
$database = "tuition";
$conn = mysqli_connect($host, $user, $password, $database);

?>

<div role="tabpanel" class="tab-pane fade in" id="sign_up">
  <form action="" method="post">
    <input type="text" class="form-control" name="register_name" placeholder="Name" required />
    <input type="text" class="form-control" name="register_ic" placeholder="IC" required />
    <input type="telephone" class="form-control" name="register_phone" placeholder="Telephone" required />
    <input type="email" class="form-control" name="register_email" placeholder="Email" required />
    <input type="password" class="form-control" name="register_password" placeholder="Password" required />
    <input type="submit" class="form-control" name="register_btn" value="Sign up" />
  </form>
</div>

<?php

if(isset($_POST['register_btn'])){
  $name = $_POST['register_name'];
  $ic = $_POST['register_ic'];
  $phone = $_POST['register_phone'];
  $email = $_POST['register_email'];
  $password = md5($_POST['register_password']);
  $result = mysqli_query($conn,"select parent.parent_ic from parent where parent_ic ='$ic'");

  if(mysqli_num_rows($result)!=1){
    mysqli_query($conn,"insert into parent(parent_name,parent_ic,parent_email,parent_contact_num,parent_password) values ('$name','$ic','$email','$phone','$password')");

?>
    <script type="text/javascript">
      alert("success");
    </script>

<?php

  }
  else{

?>
    <script type="text/javascript">
      alert("fail");
    </script>
<?php

  }
}

?>

它成功发出警报,但是没有将数据插入数据库。但是当我用硬代码将数据插入数据库时​​,它就可以工作了!为什么?

这是我单击“提交”按钮后的结果:

here is the result after I click submit button

1 个答案:

答案 0 :(得分:0)

插入数据查询后,您应该会看到打印错误

echo(“错误说明:”。mysqli_error($ conn));

我认为您的MySQL错误在那里。