hanspeare_1 0 Light Poster

Good Day,

There's a sticky that TUT about uploading image but i want the restrictions to be in this manner. But my problem here is no notice, no errors but the image file won't upload eventhough the other data has been updated, Here, check my codes. this quite long to be detailed.

<?php
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
    session_start();
    $session_id = $_SESSION['user_id'];
    if($session_id == null){
       header("location:Student_Edit.php");
       die();
    }
    include 'Connect.php';
    $flag = "";
    $student_id = $_POST['student_id'];
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $gender = $_POST['gender'];
    $date_of_birth = date("Y-m-d",strtotime($_POST['date_of_birth']));
    $contact_no = $_POST['contact_no'];
    $grade  = $_POST['grade'];
    $section = $_POST['section'];
    $LRN = $_POST['LRN'];
    $email1 = $_POST['email1'];
    $email2 = $_POST['email2'];
    $address = $_POST['address'];
    $description = $_POST['description'];

    $query = "UPDATE student_information SET first_name='$first_name',last_name='$last_name',";    
    $query .= "gender='$gender',date_of_birth='$date_of_birth',contact_no='$contact_no',grade='$grade',section='$section',";
    $query .= "LRN='$LRN',email1='$email1',email2='$email2',address='$address',description='$description'";     
    $query .= " WHERE student_id='{$_SESSION['user_id']}'";      
    $result = mysql_query($query, $link_id);
        if(mysql_error() != null){
        die(mysql_error());
    }
    if($_FILES['image']['name'] != ""){
                //$filename = $_FILES['image']['name'];
                $ext = strrchr($filename,".");
                $imagename = $student_id;
                $imagename .="_". $filename; 
                if($ext ==".jpg" || $ext ==".jpeg" || $ext ==".JPG" || $ext ==".JPEG" || $ext ==".gif" || $ext ==".GIF"){
                    $size = $_FILES['image']['size'];
                    if($size > 0 && $size < 1000000){
                        $archive_dir = "images/".$student_id;
                        $userfile_tmp_name = $_FILES['image']['tmp_name'];
                        if(move_uploaded_file($userfile_tmp_name, $archive_dir)){
       mysql_query("insert student_information set image='$imagename' where student_id='{$_SESSION['user_id']}'", $link_id); 
                            $flag = "success"; 
                            if(mysql_error()!=null){
                                die(mysql_error());
                            }
                        }
                        else{
                            if(file_exists('images/' . $imagename)) {
                                unlink('images/' . $imagename); 
                            }
                            rollbackData();
                        }
                    }
                    else{
                        if(file_exists('images/' . $imagename)) {
                            unlink('images/' . $imagename); 
                        }
                        rollbackData();
                        die("You can upload image of 1 MB size only. Please, try again.");
                    }
                }           
                else{
                    if(file_exists('images/' . $imagename)) {
                        unlink('images/' . $imagename); 
                    }
                    rollbackData();
                    die("You can upload images of .jpg, .jpeg, .gif extensions only. Please, try again. ");
                }
              }
              if($result){ 
        $flag = "success";
    }
    else{
         $flag = "error"; 
    }
    header("location:Student_Edit.php?flag=$flag&student_id='{$_SESSION['user_id']}'");   
?>     

Please let me know the lines where i get i wrong along with your reccomendation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.