Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

php - Fetch rows using mysqli

its a simple code. I want to keep a record in the database each time when a file is being uploaded. And when each time any file is being uploaded I want the user to see he/her's all uploaded files in a serial from the database. The record keeping while uploading file works fine. But the problem appears while fetching the table containing all the uploaded file information.

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

if (mysqli_connect_errno()) 
{
    printf("Connect failed: %s
", 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
", $row);
}

mysqli_close($con);
}

I can feel that there are some serious problem in coding. This is my first time working in mysqli, before I used to code using mysql. need help to know the actual problem and the solution.

Edited: it returns this,

Notice: Array to string conversion in C:xampphtdocssssupload_file.php on line 68
Array

Notice: Array to string conversion in C:xampphtdocssssupload_file.php on line 68
Array

Notice: Array to string conversion in C:xampphtdocssssupload_file.php on line 68
Array

but unfortunately this code is a part of a huge code. so here line 68 is the line where the $result = mysqli_query($con, "select * from uploads"); starts.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
$result =mysqli_query($con, "select * from uploads");
while ($row = mysqli_fetch_assoc($result))
   {
      printf ("%s
", $row['column_name_1']);
      printf ("%s
", $row['column_name_2']);
      printf ("%s
", $row['column_name_3']);
   }
mysqli_close($con);

But you should seriously consider looking at the security of your code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...