-1

I have created the database and the table and the connection with the database was successful but the data is not being sent to the database

<?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----";
    }
}
Dharman
  • 30,962
  • 25
  • 85
  • 135

2 Answers2

-1

checkout this code

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

 }

 ?>
Rajkumar Sharma
  • 554
  • 1
  • 4
  • 9
-1

Use this function for run query

mysqli_query($conn, $sql)

  • conn established Error: INSERT INTO articles (id,title,thumbnail,upvotes,views,url2) VALUES ('one','two','three','4','5',) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 2 – Milad Deraawi Aug 10 '19 at 07:12