0

i serialized form to populate the $_POST variable and insert all form varibale as a key and value to mysql

foreach ($_POST as $key => $val){
   if (!empty($val)){ 
        $fields[] = "`".$key."` = '".$val."'";
        $sql = "UPDATE `$table` SET ".implode(', ',$fields)." WHERE `$idname` = '$idval'"; 
   }
}

then the probleme is $_POST var cannot contain if form has input type="file"

here the forms

<form class="needs-validation mb-0" novalidate id="form" enctype="multipart/form-data" method="post"> 
<input type="text" name="full_name" />
<input type="file" name="photo" />
<textarea name="address"></textarea>
<button type="submit">Submit</button>
</form>

how to check if form contain file because sometime in other form there is no input file and submit is working but when form has input file the value is empty.. how to check that and change the array to insert and upload the file

can anyone help me please.. thanks..

Denis
  • 73
  • 13
  • Check if `$_FILES['photo']` has anything in it. Thats were the information about a file would be placed – RiggsFolly May 06 '21 at 09:26
  • but what if i don't need to know the specific variable name to check it.. i just want check if there is file upload in serialize forms – Denis May 06 '21 at 09:30
  • and i don't know how to check that on array – Denis May 06 '21 at 09:32
  • Then maybe `if (count($_FILES) > 0){` – RiggsFolly May 06 '21 at 09:38
  • I forgot to tell you that I actually use ajax to post,, it maybe work when i use directly action to passed with php, i still want to check it on php if process not on ajax response, maybe i will update my questing after this – Denis May 11 '21 at 21:35

0 Answers0