[FIXED] Connect to database php

Issue

What would be the correct way to connect to database ? I don't get errors but maybe my connect isn't used correctly I'm using mysqli Here is my code

 <?php 
 require_once("configur.php");

 $mysqli = new mysqli(localhost, root, password, user);

 $query_image = 'INSERT INTO fun_table (images1, images2, images3, images4) 
values( "' . $_FILES['file1']['name'] . '",
        "' . $_FILES['file2']['name'] . '",
        "' . $_FILES['file3']['name'] . '",
        "' . $_FILES['file4']['name'] . '"
   )';


   if ($mysqli->query($query_image) === TRUE) {

   echo "<script language='javascript'>\n";
   echo "alert('Upload successful!')";
   echo "</script>\n";
 } else {
  echo "Error updating record: " . $conn->error;
 }

    $mysqli->close();

   ?>

Solution

$mysqli = new mysqli(localhost, root, password, user);

You need to define those or put them in quotes.

like:

$servername = 'localhost';
$username = 'user123';
$password = 'helloworld';
$dbname ="testdatabase";

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$conn = mysqli_connect($servername, $username, $password, $dbname);
$conn->set_charset($charset);


Answered By - Marcel Schmid
Answer Checked By - Dawn Plyler (sql.easybugfix Volunteer)

Related Posts

Post a Comment