問題描述
這是一個(gè)簡(jiǎn)單的代碼.每次上傳文件時(shí),我都想在數(shù)據(jù)庫中保留一條記錄.每次上傳任何文件時(shí),我都希望用戶從數(shù)據(jù)庫中以串行方式查看他/她的所有上傳文件.上傳文件時(shí)的記錄保存工作正常.但是在獲取包含所有上傳文件信息的表時(shí)出現(xiàn)問題.
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);
}
我能感覺到編碼存在一些嚴(yán)重的問題.這是我第一次在 mysqli 中工作,之前我曾經(jīng)使用 mysql 進(jìn)行編碼.需要幫助以了解實(shí)際問題和解決方案.
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.
已它返回這個(gè),
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
但不幸的是,這段代碼是龐大代碼的一部分.所以這里的第 68 行是 $result = mysqli_query($con, "select * from uploads");
開始的那一行.
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.
推薦答案
$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);
但是您應(yīng)該認(rèn)真考慮查看代碼的安全性.
But you should seriously consider looking at the security of your code.
這篇關(guān)于使用 mysqli 獲取行的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!