gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 01:24:00 25 4
gpt4 key购买 nike

<?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

最佳答案

插入数据查询后打印错误应该可以看到

echo("错误描述:".mysqli_error($conn));

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

关于php - 为什么我不能将数据插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51345304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com