database - 无法将数据插入数据库 000webhost
问题描述
我已连接到 000webhost 数据库,它都在运行并且可以正常工作,但无法插入数据,它给了我未插入的提示!(我写的回声)我真的不知道为什么我不能上传到我连接的数据库但不会将数据发送到数据库我隐藏了所有登录信息其他一切正常!
<?php
$con=mysqli_connect("localhost", "************", "*********", "*************");
if (!$con) {
echo "Not Connected!";
} else {
echo "Connection Succeful.";
}
if (!mysqli_select_db($con, 'id5456491_emails'))
{
echo 'Database not selected!!';
}
$Name = $_POST['username'];
$Email = $_POST['email'];
$sql_store = "INSERT INTO emails1 (ID,Name,Email) VALUES (NULL,'$Name','$Email')";
$sql = mysqli_query($con, $sql_store);
if (!mysqli_query($con,$sql_store)) {
echo 'Not Inserted!';
} else {
echo "INSERTED!ss";
}
//header("refresh:2; url=referal.php");
?>
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Do+Hyeon" rel="stylesheet">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>B.F.B Hvac</title>
<style type="text/css">
#logo {
width: 50%;
margin: auto;
border:5px solid black;
border-radius: 50%
}
#content {
text-align: center;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(61, 60, 59);
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-family: 'Do Hyeon', sans-serif;
}
li a:hover {
background-color: #111;
}
#about {
background-color:rgb(61, 60, 59);
font-family: 'Do Hyeon', sans-serif;
color:white;
}
#cool {
font-family: 'Do Hyeon', sans-serif;
color: blue;
font-size: 30px;
}
#heat {
font-family: 'Do Hyeon', sans-serif;
color: red;
font-size: 30px;
}
#p1 {
font-family: 'Do Hyeon', sans-serif;
color: black;
font-size: 30px;
}
#login-form {
background-color: black;
width: 100%;
}
.ll {
background-color: grey;
height: 20px;
}
::placeholder {
color:black;
}
.ll:hover {
border-color: grey;
height: 25px;
color: white;
::placeholder {
color:white;
}
}
#btn {
background-color: grey;
}
#btn:hover {
border-color: black;
color:white;
}
</style>
</head>
<body>
<div id="head">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="quote.php">Quote</a></li>
<li><a href="gallery.html">Gallery</a></li>
<li><a href="referal.php">Referal</a></li>
<li><a href="https://www.goodmanmfg.com/product-registration">Register</a></li>
<li><a href="specials.html">Specials</a></li>
</ul>
</div>
<div id="content">
<a href="https://www.facebook.com/BFB-Heat-Air-703964289638814/">
<img src="BFBlog.jpg" id="logo">
</a>
<h1 id="about">Referal</h1>
<form action="dbh.php" method="POST">
<input type="text" name="username" placeholder="Your email">
<br><br>
<input type="text" name="email" placeholder="Referal email">
<br><br>
<input type="submit" value="Submit">
</form>
<br>
<br>
<br>
<br>
</div>
<div id="foot"></div>
<script type="text/javascript"></script>
</body>
</html>
解决方案
从下面的代码中,看起来您正在执行相同的操作INSERT
两次。
$sql_store = "INSERT INTO emails1 (ID,Name,Email) VALUES (NULL,'$Name','$Email')";
// the first INSERT
$sql = mysqli_query($con, $sql_store);
// the second same INSERT again!!
if (!mysqli_query($con,$sql_store)) {
echo 'Not Inserted!';
} else {
echo "INSERTED!ss";
}
你有任何UNIQUE constraint
在桌子上,例如:姓名,电子邮件?如果是,我怀疑第一个INSERT
成功,但第二个因UNIQUE constraint
违规而失败。您可以像这样更改代码并重试:
$sql_store = "INSERT INTO emails1 (ID,Name,Email) VALUES (NULL,'$Name','$Email')";
// only 1 INSERT
$success = mysqli_query($con, $sql_store);
// check for INSERT return status
if (!success) {
echo 'Not Inserted!';
} else {
echo "INSERTED!";
}
推荐阅读
- javascript - 如何在 onChangeText 回调中立即更改文本?
- java - Spring数据ldap不持久用户但ldap模板有效
- python - 如何跟踪字符串中的符号以进行正确操作?
- java - 如何在testng中将值传递给@test
- java - 如何在 Spring Boot 中禁用某些警告
- maxima - 如何组合两个和并分解出一个共同的元素表达式?
- java - Java右移输出负值
- ios - Xamarin Visual Studio ios 模拟器不工作
- python - Python将列表添加到另一个列表的一部分
- go - 为什么/何时从另一个 goroutine 调用上下文取消函数会导致死锁?