$_FILES IN UPLOAD IMAGE
this code 'php' upload image for CMS website, put echo error The Query Was not Working !!!
<?php session_start();
include'includes/db.php';
if(isset($_SESSION['user']) && isset($_SESSION['password'])== true){
$sel_sql = "SELECT * FROM users WHERE user_email = '$_SESSION[user]' AND user_password = '$_SESSION[password]'";
if($run_sql= mysqli_query($conn,$sel_sql)){
if(mysqli_num_rows($run_sql)==1){
}else{
header('location: ../index.php');
}
}
}else{
header('location: ../index.php');
}
$error = '' ;
if(isset($_POST['submit_post'])){
$title = strip_tags($_POST['title']);
$date = date('y-m-d h:i:s');
if($_FILES['image']['name'] != '' ){
$image_name = $_FILES['image']['name'];
$image_tmp = $_FILES['image']['tmp_name'];
$image_size = $_FILES['image']['size'];
$image_exe = pathinfo($image_name,PATHINFO_EXTENSION);
$image_path = '../img/'.$image_name;
$image_db_path = 'img/'.$image_name;
if($image_size <1000000){ //size image
if($image_exe == 'jpg' || $image_exe == 'png' ||$image_exe == 'gif' ){
if(move_uploaded_file($image_tmp,$image_path)){
$ins_sql = "INSERT INTO posts (title , description , image , category , date , author) VALUES('$title','$_POST[description]' , '$image_db_path' , '$_POST[category]','$date' ,'$_SESSION[user]')";
if(mysqli_query ($conn,$ins_sql)){
header('post_list.php');
}else{
$error = '<div class= "alert alert-danger">The Query Was not Working !</div>';
}
}else{
$error = '<div class= "alert alert-danger">Sorry , Unfortunately Image hos been uploaded!</div>';
}
}else {
$error = '<div class= "alert alert-danger"> Image Format Was not Correct !</div>';
}
}else {
$error = '<div class= "alert alert-danger"> Image File Size is mush bigger then Expext !</div>';
}
}else{
$ins_sql = "INSERT INTO posts (title , description , category , date , author) VALUES('$title','$_POST[description]' , '$_POST[category]','$date' ,'$_SESSION[user]')";
if(mysqli_query ($conn,$ins_sql)){
header('location: post_list.php');
}else{
$error = '<div class= "alert alert-danger">The Query Was not Working !!!</div>';
}
}
}
?>
this table in mysql
this result
Thank you
Aucun commentaire:
Enregistrer un commentaire