php - File is inserted in its folder without not showing any error but File name is not showing in Database table -
i uploading files through simple form of html using php & mysql. when upload file or image can moved folder name of file or image not showing in database table. problem ?
this code can check if mistake found:
enter code <?php /* attempt mysql server connection. assuming running mysql server default setting (user 'root' no password) */ $link = mysqli_connect("localhost", "root", "", "imycro"); // check connection if($link === false){ die("error: not connect. " . mysqli_connect_error()); } // escape user inputs security $name = mysqli_real_escape_string($link, $_post['name']); $email = mysqli_real_escape_string($link, $_post['email']); $country = mysqli_real_escape_string($link, $_post['country']); $phone = mysqli_real_escape_string($link, $_post['phone']); $city = mysqli_real_escape_string($link, $_post['city']); $summary = mysqli_real_escape_string($link, $_post['summary']); $jobtype = mysqli_real_escape_string($link, $_post['jobtype']); if(isset($_files["cv"]["error"])){ if($_files["cv"]["error"] > 0){ echo "error: " . $_files["cv"]["error"] . "<br>"; } else{ $allowed = array("jpg" => "image/jpg", "jpeg" => "image/jpeg", "gif" => "image/gif", "png" => "image/png"); $filename = $_files["cv"]["name"]; $filetype = $_files["cv"]["type"]; $filesize = $_files["cv"]["size"]; // verify file extension $ext = pathinfo($filename, pathinfo_extension); if(!array_key_exists($ext, $allowed)) die("error: please select valid file format."); // verify file size - 5mb maximum $maxsize = 5 * 1024 * 1024; if($filesize > $maxsize) die("error: file size larger allowed limit."); // verify myme type of file if(in_array($filetype, $allowed)){ // check whether file exists before uploading if(file_exists("documents/" . $_files["cv"]["name"])){ echo $_files["cv"]["name"] . " exists."; } else{ move_uploaded_file($_files["cv"]["tmp_name"], "documents/" . $_files["cv"]["name"]); echo "your file uploaded successfully."; } } else{ echo "error: there problem uploading file - please try again."; } } } else{ echo "error: invalid parameters - please contact server administrator."; } // file upload code ends here ///////////////////////////// // attempt insert query execution $sql = "insert work (name, email, country, phone, city, summary, jobtype) values ('$name', '$email', '$country' , '$phone' , '$city', '$summary' , '$jobtype')"; if(mysqli_query($link, $sql)){ echo "records added successfully."; } else{ echo "error: not able execute $sql. " . mysqli_error($link); } // close connection mysqli_close($link); ?>
Comments
Post a Comment