Getting rows with mysqli

its simple code. I want to save a record in the database every time a file is uploaded. And when every time a file is downloaded, I want the user to see all of his downloaded files in the series from the database. Saving a record while downloading a file works fine. But the problem arises when retrieving a table containing all the information about the downloaded file.

//connetion code 
$con = mysqli_connect("localhost", "root", "", "sss");

if (mysqli_connect_errno()) 
{
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

//file upload code
move_uploaded_file($_FILES["file"]["tmp_name"],"C:/xampp/htdocs/" . $_FILES["file"]["name"]);
mysqli_query($con, "INSERT INTO uploads ( filename, uploaded_on) VALUES ( '{$_FILES['file']['name']}', NOW());");
echo "Stored in: " . "C:/xampp/htdocs/" . $_FILES["file"]["name"];

//fetch rows 
$result =mysqli_query($con, "select * from uploads");

while ($row = mysqli_fetch_array($result))
{
    printf ("%s\n", $row);
}

mysqli_close($con);
}

I feel that there are some serious coding issues. This is my first mysqli experience before I used code using mysql. need help to find out the actual problem and solution.

Edited: it returns this,

Notice: Array to string conversion in C:\xampp\htdocs\sss\upload_file.php on line 68
Array

Notice: Array to string conversion in C:\xampp\htdocs\sss\upload_file.php on line 68
Array

Notice: Array to string conversion in C:\xampp\htdocs\sss\upload_file.php on line 68
Array

, , . 68 - , $result = mysqli_query($con, "select * from uploads");.

0
1
$result =mysqli_query($con, "select * from uploads");
while ($row = mysqli_fetch_assoc($result))
   {
      printf ("%s\n", $row['column_name_1']);
      printf ("%s\n", $row['column_name_2']);
      printf ("%s\n", $row['column_name_3']);
   }
mysqli_close($con);

.

+1

Source: https://habr.com/ru/post/1620666/


All Articles