studentinfo.php

//Simpan berita 
    if (isset($_POST['ok'])){

        if (empty($_GET['student_id']))
            {
            $sqlstr = "INSERT INTO `student`(group_id, student_name, student_address, student_telp, student_hp, whatsapp, skype, facebook, twitter) VALUES('".$group_id."','".$student_name."','".$student_address."','".$student_telp."','".$student_hp."','".$whatsapp."','".$skype."','".$facebook."','".$twitter."')";
            include('studentinfopic_upload.php'); 
            }
        else
        {
            $sqlstr = "UPDATE `student` SET student_name='".$student_name."', student_address='".$student_address."', student_telp='".$student_telp."', student_hp='".$student_hp."', whatsapp='".$whatsapp."', skype='".$skype."', facebook='".$facebook."', twitter='".$twitter."' WHERE student_id=".$_GET['student_id'];
            include('studentinfopic_upload.php'); 
        }

        $result = mysql_query($sqlstr) or die(mysql_error());

        //Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
        //if (empty($_REQUEST['id']))   kirimEmail($idKategori, $judul, $news);
        $confirmation = ($result) ? "Data telah tersimpan." : "Gagal menyimpan data.";  
    }

        //Load berita
    if (!empty($_GET['student_id'])){
        $result = mysql_query("SELECT * FROM `student` WHERE student_id =".$_GET['student_id']) or die(mysql_error());
        $data = mysql_fetch_array($result);
        $student_id = $data['student_id'];
        $student_name = $data['student_name'];
        $student_address = $data['student_address'];
        $student_telp = $data['student_telp'];
        $student_hp = $data['student_hp'];
        $whatsapp = $data['whatsapp'];
        $skype = $data['skype'];
        $facebook = $data['facebook'];
        $twitter = $data['twitter'];
        $student_picture = $data['student_picture'];

    }
    else {
    echo "unable to select data".'<br>';
    echo "student_id is empty";
    }
    ?>
    <div align="center">
        <div style="width:800px;text-align:left;">
        <?php echo $confirmation;?>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF'] .'?student_id='. $student_id;?>">
            <!-- <input type="hidden" name="id" value="<?php// echo $id; ?>"/>-->
            <table>
                <tr>
                    <td>Student Picture</td>              
                    <td><input type="file" size="45" name="uploadfile" id="uploadfile" class="file margin_5_0" onchange="ajaxUpload(this.form);" /></td>
                </tr>
                <tr>
                    <td>Student Name</td>             
                    <td><input type="text" size="50px" name="student_name" value="<?php echo $student_name; ?>"></td>
                </tr>
                <tr>
                    <td>Student Address</td>
                    <td><input type="text" size="10px" name="student_address" value="<?php echo $student_address; ?>"/></td>
                </tr>
                <tr>
                    <td>Student Telp</td>
                    <td><input type="text" size="10px" name="student_telp" value="<?php echo $student_telp; ?>"/></td>
                </tr>
                <tr>
                    <td>Student Hp</td>
                    <td><input type="text" size="50px" name="student_hp" value="<?php echo $student_hp; ?>"/></td>
                </tr>
                <tr>             
                    <td><input type="submit" name="ok" value="Simpan"/></td>
              </tr>
            </table>
        </form>
        </div>
    </div>
</div>    

studentinfopic_upload.php

<?php

// upload picture untuk student profile 

//----------------------------------------- start edit here ---------------------------------------------//
$script_location = "http://demo.zmeutz.com/image_upload/"; // location of the script
$maxlimit = 1048576; // maxim image limit
$folder = "student_profile"; // folder where to save images

// requirements 4 x 6 cm atau 151 x 201 px
$minwidth = 141; // minim width
$minheight = 191; // minim height
$maxwidth = 161; // maxim width
$maxheight = 211; // maxim height

//thumbnails - 1 or 0 to allow or disallow
$thumb = 0; // allow to create thumb n.1
$thumb2 = 0; // allow to create thumb n.2
$thumb3 = 0; // allow to create thumb n.3

// allowed extensions
$extensions = array('.png', '.gif', '.jpg', '.jpeg','.PNG', '.GIF', '.JPG', '.JPEG');
//----------------------------------------- end edit here ---------------------------------------------//


// insert into mysql database and show success message
//          mysql_query("INSERT INTO `image_upload` (`id`, `image`, `thumbnail`, `thumbnail2`, `thumbnail3`, `location` ) VALUES (NULL, '". $image ."', 'thumb-". $image ."', 'thumb2-". $image ."', 'thumb3-". $image ."','". $location ."')");


// check that we have a file
    if((!empty($_FILES["uploadfile"])) && ($_FILES['uploadfile']['error'] == 0)) {
        echo "hello";
    // check extension
    $extension = strrchr($_FILES['uploadfile']['name'], '.');
    if (!in_array($extension, $extensions)) {
        echo 'wrong file format, alowed only .png , .gif, .jpg, .jpeg
        <script language="javascript" type="text/javascript">window.top.window.formEnable();</script>';
    } else {

// get file size
$filesize = $_FILES['uploadfile']['size'];

    // check filesize
    if($filesize > $maxlimit){ 
        echo "File size is too big.";
    } else if($filesize < 1){ 
        echo "File size is empty.";
    } else {

// temporary file
$uploadedfile = $_FILES['uploadfile']['tmp_name'];

// capture the original size of the uploaded image
list($width,$height) = getimagesize($uploadedfile);

    // check if image size is lower
    if($width < $minwidth || $height < $minheight){ 
        echo 'Image is to small. Required minimum '.$minwidth.'x'.$minheight.'
        <script language="javascript" type="text/javascript">window.top.window.formEnable();</script>';
    } else if($width > $maxwidth || $height > $maxheight){ 
        echo 'Image is to big. Required maximum '.$maxwidth.'x'.$maxheight.'
        <script language="javascript" type="text/javascript">window.top.window.formEnable();</script>';
    } else {

// all characters lowercase
$filename = strtolower($_FILES['uploadfile']['name']);

// replace all spaces with _
$filename = preg_replace('/\s/', '_', $filename);

// extract filename and extension
$pos = strrpos($filename, '.'); 
$basename = substr($filename, 0, $pos); 
$ext = substr($filename, $pos+1);

// get random number
$rand = time();

// image name
$image = $basename .'-'. $rand . "." . $ext;

// check if file exists
$check = $folder . '/' . $image;
    if (file_exists($check)) {
        echo 'Image already exists';
    } else {

// check if it's animate gif
$frames = exec("identify -format '%n' ". $uploadedfile ."");
    if ($frames > 1) {
        // yes it's animate image
        // copy original image
        copy($_FILES['uploadfile']['tmp_name'], $folder . '/' . $image);

        // orignal image location
        $write_image = $folder . '/' . $image;
        //ennable form
        echo '<img src="' . $write_image . '" alt="'. $image .'" alt="'. $image .'" width="500" /><br />
<input type="text" name="location" value="[IMG]'.$script_location.''.$write_image.'[/IMG]" class="location corners" />
<script language="javascript" type="text/javascript">window.top.window.formEnable();</script>';
    } else {

// create an image from it so we can do the resize
 switch($ext){
  case "gif":
    $src = imagecreatefromgif($uploadedfile);
  break;
  case "jpg":
    $src = imagecreatefromjpeg($uploadedfile);
  break;
  case "jpeg":
    $src = imagecreatefromjpeg($uploadedfile);
  break;
  case "png":
    $src = imagecreatefrompng($uploadedfile);
  break;
 }

// copy original image
copy($_FILES['uploadfile']['tmp_name'], $folder . '/' . $image);

// orignal image location
$write_image = $folder . '/' . $image;

if ($thumb == 1){
// create first thumbnail image - resize original to 80 width x 80 height pixels 
$newheight = ($height/$width)*80;
$newwidth = 80;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagealphablending($tmp, false);
imagesavealpha($tmp,true);
$transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefilledrectangle($tmp, 0, 0, $newwidth, $newheight, $transparent);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// write thumbnail to disk
$write_thumbimage = $folder .'/thumb-'. $image;
 switch($ext){
  case "gif":
    imagegif($tmp,$write_thumbimage);
  break;
  case "jpg":
    imagejpeg($tmp,$write_thumbimage,100);
  break;
  case "jpeg":
    imagejpeg($tmp,$write_thumbimage,100);
  break;
  case "png":
    imagepng($tmp,$write_thumbimage);
  break;
 }
}

if ($thumb2 == 1){
// create second thumbnail image - resize original to 125 width x 125 height pixels 
$newheight = ($height/$width)*125;
$newwidth = 125;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagealphablending($tmp, false);
imagesavealpha($tmp,true);
$transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefilledrectangle($tmp, 0, 0, $newwidth, $newheight, $transparent);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// write thumbnail to disk
$write_thumb2image = $folder .'/thumb2-'. $image;
 switch($ext){
  case "gif":
    imagegif($tmp,$write_thumb2image);
  break;
  case "jpg":
    imagejpeg($tmp,$write_thumb2image,100);
  break;
  case "jpeg":
    imagejpeg($tmp,$write_thumb2image,100);
  break;
  case "png":
    imagepng($tmp,$write_thumb2image);
  break;
 }
}

if ($thumb3 == 1){
// create third thumbnail image - resize original to 125 width x 125 height pixels 
$newheight = ($height/$width)*250;
$newwidth = 250;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagealphablending($tmp, false);
imagesavealpha($tmp,true);
$transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefilledrectangle($tmp, 0, 0, $newwidth, $newheight, $transparent);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// write thumbnail to disk
$write_thumb3image = $folder .'/thumb3-'. $image;
 switch($ext){
  case "gif":
    imagegif($tmp,$write_thumb3image);
  break;
  case "jpg":
    imagejpeg($tmp,$write_thumb3image,100);
  break;
  case "jpeg":
    imagejpeg($tmp,$write_thumb3image,100);
  break;
  case "png":
    imagepng($tmp,$write_thumb3image);
  break;
 }
}

// all is done. clean temporary files
imagedestroy($src);
imagedestroy($tmp);

// image preview
if ($thumb == 1){
echo "<img src='" . $write_thumbimage . "' alt='". $image ."' /><br />
<input type='text' name='location' value='[IMG]".$script_location."". $write_thumbimage ."[/IMG]' class='location corners' /><br />
<br />";
}
if ($thumb2 == 1){
echo "<img src='" . $write_thumb2image . "' alt='". $image ."' /><br />
<input type='text' name='location' value='[IMG]".$script_location."". $write_thumb2image ."[/IMG]' class='location corners' /><br />
<br />";
}
if ($thumb3 == 1){
echo "<img src='" . $write_thumb3image . "' alt='". $image ."' /><br />
<input type='text' name='location' value='[IMG]".$script_location."". $write_thumb3image ."[/IMG]' class='location corners' /><br />
<br />";
}
echo "<img src='" . $write_image . "' alt='". $image ."' alt='". $image ."' width='500' /><br />
<input type='text' name='location' value='[IMG]".$script_location."".$write_image."[/IMG]' class='location corners' />
<script language='javascript' type='text/javascript'>window.top.window.formEnable();</script>
<div class='clear'></div>";
      }
    }
  }
}
    // database connection
    include('../includes/koneksi.php');

            // insert into mysql database and show success message
            // mysql_query("INSERT INTO `image_upload` (`id`, `image`, `thumbnail`, `thumbnail2`, `thumbnail3`, `location` ) VALUES (NULL, '". $image ."', 'thumb-". $image ."', 'thumb2-". $image ."', 'thumb3-". $image ."','". $location ."')");

      $sqlstr = mysql_query("UPDATE student SET student_picture='". $student_picture ."' WHERE student_id='".$_GET['student_id']."'");
      echo $sqlstr;
      //$sqlstr = "UPDATE static_page SET page='".$page."', judul='".$judul."', isi_berita='".$news."' WHERE post_id=".$_GET['post_id'];


        // error all fields must be filled
    }} else {
        echo '<div class="wrong">You must to fill all fields!</div>'; }

?>

Looks like it doesn't want to process this query to insert student_picture:

$sqlstr = mysql_query("UPDATE student SET student_picture='". $student_picture ."' WHERE student_id='".$_GET['student_id']."'");

I keep receiving this message eventhough I already insert image:
You must to fill all fields!

Please help.

um i think you should post the important bits not the WHOLE thing. coz i don't think the members want to have to read all that. make it easier for them to read. help them, help you.

Be a part of the DaniWeb community

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