在這段代碼中,如果我沒有上傳圖像,那麼我的插入查詢不起作用(如果部分不起作用)。如果我上傳圖像,那麼它工作(或其他部分工作)。在插入命令中沒有圖像的數據庫不會更新
CODE
if (isset($_POST['submit'])) {
include('config.php');
$Title = mysql_real_escape_string($_POST["Title"]);
$Description = mysql_real_escape_string($_POST["description"]);
$imageType = mysql_real_escape_string($_FILES["image"]["type"]);
$DateTime = date('Y/m/d H:i:s');
$Category = $_POST["select_category"];
//This part is not Working(Below If Part)
if(empty($_FILES["image"]["tmp_name"]) || !is_uploaded_file($_FILES["image"]["tmp_name"])) {
mysql_query("INSERT INTO `News` VALUES('','$Title','$Description','$Category',1,'$DateTime',1)");
echo "<a href=list.php><img src=../img/success.gif /><span>View List</span></a>";
}
//This part working(below else Part)
else
{
$imageName = mysql_real_escape_string($_FILES["image"]["name"]);
$imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
mysql_query("INSERT INTO `News` VALUES('','$Title','$imageName','$Description','$imageData','$Category',1,'$DateTime',1)");
echo "<a href=list.php><img src=../img/success.gif /><span>View Listx</span></a>";
}
//some code here
誰能幫我解決這個問題?提前致謝。
完全相同的條件寫入做同樣的工作。問題是什麼? – Bilal
當我提交沒有image.then它不工作..沒有錯誤,但沒有工作 – TechGuy
爲什麼你甚至想執行一個查詢如果'$ _FILES'是空的或沒有上傳,首先?只是讓它「死();」或什麼。只是扭轉你的條件。 –