Reputation: 6103
I'm trying to make an update form for the records in my DB. This is the form:
<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>
The values of all the input fields (except for 'file') are set with jQuery, and they're all set correctly, I double checked.
Then I have this jQuery function that is being executed once I hit the submit button:
$("#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
}
});
What I want to do in the API.php file is this: check if a new image file is being uploaded, if not - set new_image_filename to the current filename (request it from the curr_image_filename
hidden input field), and if yes - delete the currently set file from the server, upload the new image, set new_image_filename to its name and update the DB. So I wrote this code:
$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"]);
}
}
But I'm keep getting this error message: Undefined index: curr_image_filename in mypath\API.php on line 21, which is this: $newImageFileName = $_REQUEST["curr_image_filename"];
Why is it happening and how can I fix it?
Upvotes: 0
Views: 205
Reputation: 360762
id != name
:
<input type="hidden" value="" id="curr_image_filename" />
^^----must be "name" to be submitted as a form field
No name, no submission. And IDs do not count as names.
Upvotes: 2