I have some problem about uploading and database. I upload the file (abc.jpg) and the file already insert to the folder name (uploads). But when I check in database (php), the file did not enter. Here is my code. Hope anyone can help me.Thank you.

<? include "conn.php";?>
    $target = "uploads/"; 
    $allowedExts = array("jpg", "jpeg");
    $extension = end(explode(".", $_FILES["file_upload"]["name"]));
    $target = $target . basename( $_FILES['file_upload']['name']);
    $date = date("Y-m-d H:i:s");

    //Function to generate image thumbnails
    function make_thumb($src, $dest, $desired_width) {

        /* read the source image */
        $source_image = imagecreatefromjpeg($src);
        $width = imagesx($source_image);
        $height = imagesy($source_image);

        /* find the "desired height" of this thumbnail, relative to the desired width  */
        $desired_height = floor($height * ($desired_width / $width));

        /* create a new, "virtual" image */
        $virtual_image = imagecreatetruecolor($desired_width, $desired_height);

        /* copy source image at a resized size */
        imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);

        /* create the physical thumbnail image to its destination with 100% quality*/
        imagejpeg($virtual_image, $dest,100);

    //check for allowed extensions
    if ((($_FILES["file_upload"]["type"] == "image/jpg")|| ($_FILES["file_upload"]["type"] == "image/jpeg"))&& in_array($extension, $allowedExts))
        $photoname = $_FILES["file_upload"]["name"];
        if (file_exists("../uploads/" . $photoname))
            die( '<div class="error">Maaf <b>'. $photoname . '</b> telah dimuatnaik sebelum ini</div>');

        if(move_uploaded_file($_FILES['file_upload']['tmp_name'], $target)) 
            $query = "INSERT INTO updown (nama_file,tkh_muatnaik) VALUES ('$photoname','$date')";
            $sql = "SELECT MAX(id_gambar) FROM updown";
            $max = mysql_query($sql);
            $row = mysql_fetch_array($max);
            $maxId = $row['MAX(id_gambar)'];

            $type = $_FILES["file_upload"]["type"];
                case "image/jpeg":
                $ext = ".jpeg";
                case "image/jpg";
                $ext = ".jpg";

            //define arguments for the make_thumb function
            $source = "uploads/".$photoname;
            $destination = "thumbnails/thumb_". $maxId . $ext ."";          
            //specify your desired width for your thumbnails
            $width = "282";
            //Finally call the make_thumb function

            $msg = '<div class="success">
                        <b>Muatnaik: </b>' . basename($photoname) . '<br />
                        <b>Format: </b>' . $_FILES["file_upload"]["type"] . '<br />
                        <b>Size: </b>' . ceil(($_FILES["file_upload"]["size"] / 1024)) . 'Kb<br />
                $msg = '<div class="error">Maaf, muatnaik gambar tidak berjaya</div>';
            $msg = '<div class="error">Format gambar ini tidak diterima!</div>';
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
    <link rel="stylesheet" href="style.css" />
    <link rel="stylesheet" type="text/css" media="all" href="js/jsDatePick_ltr.min.css" />
<script type="text/javascript" src="js/jsDatePick.min.1.3.js"></script>

<script type="text/javascript">  
function redirectpage(){

    window.location = "daftar_majlis_1.php";

<link href="css/style_galeri.css" rel="stylesheet" type="text/css" />


<table width="70%"  align="center">
<td colspan="2" class="header"></td>
    <td width="79%"><? include "menu_admin.htm"; ?></td>
    <td><H3 class="main_title">Muat Naik Gambar Disini</H3>(<a href="galeri_admin.php" >Lihat Galeri</a>)
<div id="upload">
<?php echo $msg; ?>
<form action="" method="post" enctype="multipart/form-data">
<label for="file">Gambar:</label>
<input type="file" name="file_upload" id="upload_file" />
<input type="submit" name="submit" value="Muatnaik" />
    <td width="21%">&nbsp;</td>


Add error-handling to your query, so you can see if it fails.

Be a part of the DaniWeb community

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