我已经创建了数据库和表,并且与数据库的连接成功,但是没有将数据发送到数据库
<?php
$mysqli = mysqli_connect('****************', '***************', '*************', '******posts');
if ($mysqli) {
echo "conn established";
} else {
echo "conn failed";
}
if (isset($_POST["submit"])) {
$one = "one";
$two = "two";
$three = "three";
$four = "four";
$five = "five";
$push = mysqli_query($mysqli, "INSERT INTO articles
(id,title,thumbnail,upvotes,views,url)
VALUES ('$one','$two','$three','$four','$five')");
if ($push) {
echo "---------pushed----------";
} else {
echo "-----not pushed----";
}
}
答案 0 :(得分:-1)
签出此代码
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "nepalroute";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
if(isset($_POST["submit"])) {
$one = "one";
$two = "two";
$three = "three";
$four = "four";
$five = "five";
$sql = "INSERT INTO articles (id,title,thumbnail,upvotes,views,url)
VALUES ('$one','$two','$three','$four','$five')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
?>
答案 1 :(得分:-1)
将此功能用于运行查询
mysqli_query($ conn,$ sql)