2014-02-18 25 views
0

我正在嘗試爲我的數據庫中的記錄創建更新表單。這是形式:

<form id="form_update_ad" method="post" action="inc/API.php" enctype="multipart/form-data"> 
    <input type="text" name="input_publisher" id="input_publisher_edt" placeholder="Name" /> 
    <input type="text" name="input_link" id="input_link_edt" placeholder="Link" /> 
    <input type="file" name="file2Upload_edt" id="file2Upload_edt" /> 
    <input type="submit" value="" id="btnUpdate" /> 
    <input type="hidden" name="command" value="update_ad" /> 
    <input type="hidden" value="" id="curr_image_filename" /> 
    <input type="hidden" value="" id="curr_add_id" /> 
</form> 

所有輸入字段的值(除「文件」)設置與jQuery,而且都設置正確,我仔細檢查了。

然後,我有一次我打提交按鈕正在執行這個jQuery函數:

$("#form_update_ad").on("submit", function(event){ 
    event.preventDefault(); 
    // some validations... 
    if(errors.length==0) 
    { 
     $(this).off("submit"); 
     this.submit(); 
    } 
    else 
    { 
     // if there are errors - do something here 
    } 
}); 

我想在API.php文件做的是:檢查是否有新的圖像文件將被否則 - 將new_image_filename設置爲當前文件名(從curr_image_filename隱藏的輸入字段中請求它),如果是 - 從服務器上刪除當前設置的文件,上傳新映像,將new_image_filename設置爲其名稱並更新數據庫。在mypath中\ API.php curr_image_filename第21行,這是這樣的::所以我寫了這個代碼:

$newImageFileName = ""; 
if($_FILES["file2Upload_edt"]["name"]=='') 
{ 
    $newImageFileName = $_REQUEST["curr_image_filename"]; 
} 
else 
{ 
    if(delete_file_from_server($_REQUEST["curr_image_filename"])) 
    { 
     $newImageFileName = saveImage2Server("file2Upload_edt"); 
     update_ad($_REQUEST["curr_ad_id"],$_REQUEST["input_publisher"], $newImageFileName, $_REQUEST["input_link"]); 
    } 
} 

但我不斷收到此錯誤信息:未定義指數$newImageFileName = $_REQUEST["curr_image_filename"];

爲什麼會發生我該如何解決它?

回答

2

id != name

<input type="hidden" value="" id="curr_image_filename" /> 
           ^^----must be "name" to be submitted as a form field 

沒有名字,沒有提交。而身份證不算作名字。

+0

謝謝!我不再有'未定義的索引'消息! A也注意到我將調用放置到'update_ad()'函數的另一個問題(如果沒有新文件要上傳,代碼不會到達它),所以我改變了它。現在我遇到了一些與我的PDO更新查詢有關的問題,將不得不查看它。再次感謝您的幫助! – Igal