Hello,
I am trying to input pictures in student profile yet it doesn't work yet. I wonder why?
studentinfo.php
<?php
include('includes/koneksi.php');
$student_id = isset($_GET['student_id']) ? $_GET['student_id'] : '';
$group_id = isset($_POST['group_id']) ? $_POST['group_id'] : '';
$access_level_id = isset($_POST['access_level_id']) ? $_POST['access_level_id'] : '';
$stu_fname = isset($_POST['stu_fname']) ? $_POST['stu_fname'] : '';
$stu_lname = isset($_POST['stu_fname']) ? $_POST['stu_lname'] : '';
$stu_email = isset($_POST['stu_email']) ? $_POST['stu_email'] : '';
$stu_address = isset($_POST['stu_address']) ? $_POST['stu_address'] : '';
$stu_telp = isset($_POST['stu_telp']) ? $_POST['stu_telp'] : '';
$stu_hp = isset($_POST['stu_hp']) ? $_POST['stu_hp'] : '';
$stu_wa = isset($_POST['stu_wa']) ? $_POST['stu_wa'] : '';
$stu_skype = isset($_POST['stu_skype']) ? $_POST['stu_skype'] : '';
$stu_facebook = isset($_POST['stu_facebook']) ? $_POST['stu_facebook'] : '';
$stu_twitter = isset($_POST['stu_twitter']) ? $_POST['stu_twitter'] : '';
$confirmation = isset($_POST['confirmation']) ? $_POST['confirmation'] : '';
$confirmation2 = isset($_POST['confirmation2']) ? $_POST['confirmation2'] : '';
$newfilename = isset($_POST['file']) ? $_POST['file'] : '';
//Simpan student profile
if (isset($_POST['ok'])){
//echo "Check what's inside files : ".$_FILES['file'];
if (empty($_GET['student_id']))
{
// Picture Upload
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 41943040) //40MB
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
} else {
echo "Successfully upload pictures";
//echo "Upload: " . $_FILES["file"]["name"] . "<br>";
//echo "Type: " . $_FILES["file"]["type"] . "<br>";
//echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
//echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
$filename = $_FILES["file"]["name"];
$i = (rand());
$ii = (rand());
$iii = (rand());
$newfilename = $ii.$iii.$i.$filename;
//echo $_FILES["file"]["name"] . " new file name is $newfilename. ";
} else {
$filename = $_FILES["file"]["name"];
$i = (rand());
$newfilename = $i.$filename;
move_uploaded_file($_FILES["file"]["tmp_name"],
"../upload/" . $newfilename);
//echo "Stored in: " . "upload/" . $newfilename;
}
}
} else {
echo "No picture Uploaded";
}
$filename = $_FILES["file"]["name"];
$username = substr($stu_fname, 0, 1).$stu_lname;
$username = strtolower($username);
// default password for new student
$encrypteddefaultpassword = MD5('squprime');
$sqlstr = "INSERT INTO student(group_id, access_level_id, newfilename, filename, stu_username, stu_password, stu_fname, stu_lname, stu_email, stu_address, stu_telp, stu_hp, stu_wa, stu_skype, stu_facebook, stu_twitter) VALUES('".$group_id."','".$access_level_id."' , '".$newfilename."', '".$filename."', '".$username."', '".$encrypteddefaultpassword."', '".$stu_fname."','".$stu_lname."', '".$stu_email."', '".$stu_address."','".$stu_telp."','".$stu_hp."','".$stu_wa."','".$stu_skype."','".$stu_facebook."','".$stu_twitter."')";
$studentidResult = mysql_query("SELECT student_id FROM student ORDER BY student_id DESC") or die(mysql_error());
$dataid = mysql_fetch_array($studentidResult);
$student_id = $dataid['student_id'];
$sqlstr2 = "INSERT INTO study_report(group_id, student_id, stu_fname, stu_lname) VALUES('".$group_id."', '".$student_id."', '".$stu_fname."','".$stu_lname."')";
}
else
{
// Picture Upload
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 41943040) //40MB
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
} else {
//echo "Successfully upload pictures";
//echo "Upload: " . $_FILES["file"]["name"] . "<br>";
//echo "Type: " . $_FILES["file"]["type"] . "<br>";
//echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
//echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
$filename = $_FILES["file"]["name"];
$i = (rand());
$ii = (rand());
$iii = (rand());
$newfilename = $ii.$iii.$i.$filename;
//echo $_FILES["file"]["name"] . " new file name is $newfilename. ";
} else {
$filename = $_FILES["file"]["name"];
$i = (rand());
$newfilename = $i.$filename;
move_uploaded_file($_FILES["file"]["tmp_name"],
"../upload/" . $newfilename);
//echo "Stored in: " . "upload/" . $newfilename;
}
}
} else {
echo "No picture uploaded";
}
$filename = $_FILES["file"]["name"];
$username = substr($stu_fname, 0, 1).$stu_lname;
$username = strtolower($username);
$student_id = $_REQUEST['student_id'];
// Query to get student picture filename
$result = mysql_query("SELECT newfilename FROM student WHERE student_id =".$student_id) or die(mysql_error());
$data1 = mysql_fetch_assoc($result);
$pic_filename = $data1['newfilename'];
if($result){
unlink('../upload/'.$pic_filename);
}
$sqlstr = "UPDATE `student` SET group_id='".$group_id."', access_level_id='".$access_level_id."', newfilename='".$newfilename."', filename='".$filename."', stu_username='".$username."', stu_fname='".$stu_fname."', stu_lname='".$stu_lname."', stu_email='".$stu_email."', stu_address='".$stu_address."', stu_telp='".$stu_telp."', stu_hp='".$stu_hp."', stu_wa='".$stu_wa."', stu_skype='".$stu_skype."', stu_facebook='".$stu_facebook."', stu_twitter='".$stu_twitter."' WHERE student_id=".$_GET['student_id'];
$sqlstr2 = "UPDATE `study_report` SET group_id='".$group_id."', stu_fname='".$stu_fname."', stu_lname='".$stu_lname."' WHERE student_id='".$_GET['student_id']."'";
}
$result = mysql_query($sqlstr) or die(mysql_error());
$result2 = mysql_query($sqlstr2) 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 has been saved." : "Fail to save data.";
//$confirmation2 = ($result2) ? "Study Report Data has been saved." : "Fail to save study report data.";
}
//Load Student Profile
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'];
$stu_fname = $data['stu_fname'];
$stu_lname = $data['stu_lname'];
$stu_email = $data['stu_email'];
$stu_address = $data['stu_address'];
$stu_telp = $data['stu_telp'];
$stu_hp = $data['stu_hp'];
$stu_wa = $data['stu_wa'];
$stu_skype = $data['stu_skype'];
$stu_facebook = $data['stu_facebook'];
$stu_twitter = $data['stu_twitter'];
$stu_picture = $data['stu_picture'];
$newfilename = $data['newfilename'];
$access_level_id = $data['access_level_id'];
}
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;?>
<?php //echo $confirmation2;?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] .'?student_id='. $student_id;?>" enctype="multipart/form-data">
<!-- <input type="hidden" name="id" value="<?php// echo $id; ?>"/>-->
<table>
<tr>
<td>Student Picture</td>
<td>
<?php echo "<img src='../upload/".$newfilename."'>"; ?><br>
<input type="file" value="upload" name="file"/><br><br>
</td>
</tr>
<tr>
<td>Group Name</td>
<td>
<?php
$rs = mysql_query("SELECT * FROM `group`") or die(mysql_error());
echo "<select name='group_id'>";
while($data = mysql_fetch_array($rs)){
echo "<option value='".$data['group_id']."'>".$data['group_name']."</option>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td>Access</td>
<td>
<?php
echo '<select name="access_level_id">';
echo '<option value="3" ';
if($access_level_id=="3"){echo 'selected="selected" ';}
echo '>Student</option>';
echo '<option value="4" ';
if($access_level_id=="4"){echo 'selected="selected" ';}
echo '>Student Group Master</option>';
echo '</select>';
?>
</td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" size="50px" name="stu_fname" value="<?php echo $stu_fname; ?>"></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" size="50px" name="stu_lname" value="<?php echo $stu_lname; ?>"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" size="50px" name="stu_email" value="<?php echo $stu_email; ?>"></td>
</tr>
<tr>
<td>Student Address</td>
<td><input type="text" size="50px" name="stu_address" value="<?php echo $stu_address; ?>"/></td>
</tr>
<tr>
<td>Student Telp</td>
<td><input type="text" size="30px" name="stu_telp" value="<?php echo $stu_telp; ?>"/></td>
</tr>
<tr>
<td>Student Hp</td>
<td><input type="text" size="30px" name="stu_hp" value="<?php echo $stu_hp; ?>"/></td>
</tr>
<tr>
<td>Whatsapp</td>
<td><input type="text" size="50px" name="stu_wa" value="<?php echo $stu_wa; ?>"/></td>
</tr>
<tr>
<td>Skype</td>
<td><input type="text" size="50px" name="stu_skype" value="<?php echo $stu_skype; ?>"/></td>
</tr>
<tr>
<td>Facebook</td>
<td><input type="text" size="50px" name="stu_facebook" value="<?php echo $stu_facebook; ?>"/></td>
</tr>
<tr>
<td>Twitter</td>
<td><input type="text" size="50px" name="stu_twitter" value="<?php echo $stu_twitter; ?>"/></td>
</tr>
<tr>
<td></td>
<td><br><input type="submit" name="ok" value="Save" class="abutton"/></td>
<?php
//$username = substr($stu_fname, 0, 1).$stu_lname;
//echo strtolower($username);
?>
</tr>
</table>
</form>
</div>
</div>
</div>