概述
$servername = "localhost";
$username = "root";
$password = "pass";
$dbname = "test";
$name="admin";
$pass="passerino";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}else {
echo nl2br("Conected n");
}
$sqlin="INSERT INTO data_test (username, password) VALUES ('valname','valpass')";
$result=$conn->query($sqlin);
if ($conn->query($sqlin) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sqlin . "
" . $conn->error;
}
$conn->close();
include_once "read.php";
?>
Hello i have this simple .php file to insert data into mySQL database,but instead of once it does it two times with one request.How can i stop this?I am using wamp server x64,chrome,php 5.5.12;
P.S read.php displays the data table
解决方案
change this code
$sqlin="INSERT INTO data_test (username, password) VALUES ('valname','valpass')";
$result=$conn->query($sqlin);
if ($conn->query($sqlin) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sqlin . "
" . $conn->error;
}
$conn->close();
include_once "read.php";
to
$sqlin="INSERT INTO data_test (username, password) VALUES ('valname','valpass')";
$result=$conn->query($sqlin);
if ($result === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sqlin . "
" . $conn->error;
}
$conn->close();
include_once "read.php";
Because if you run this line $conn->query($sqlin); twice it will run your query twice and insert record in database two time
最后
以上就是完美书包为你收集整理的php mysql 重复提交数据,PHP两次将数据插入到MySQL中,而不是一次的全部内容,希望文章能够帮你解决php mysql 重复提交数据,PHP两次将数据插入到MySQL中,而不是一次所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复