我是靠谱客的博主 完美书包,最近开发中收集的这篇文章主要介绍php mysql 重复提交数据,PHP两次将数据插入到MySQL中,而不是一次,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

$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中,而不是一次所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部