Asalamualaikum.
Korang pernah tak sangkut lama dekat part nak upload and update gambar profil dekat website dan app korang? Pastu korang stackoverflow mana mana pun semua outcome berakhir dengan error. So cuba guna coding saya dibawah ini. Kalau berkesan, alhamdulillah kalau tak berkesan cuba lagi.
Sebagai upah atau balasan saya share coding ini, doakan saya dimurahkan rezeki, please subscribe my youtube channel KhaidirKhaizuki.
kk_public.php
<?php
session_start();
if(!isset($_SESSION["email"])){
echo "<script>";
echo "alert('Anda telah log keluar, sila log masuk semula.');";
echo "location = 'index.php'";
echo "</script>";
}
?>
<?php
include_once("dbconfig.php");
if(isset($_REQUEST['submit'])){ // If submit button is triggered,
$conn= mysqli_connect("localhost","id15455841_members99","sistemBJB-2020","id15455841_adproject2020") or die ("could not connect to mysql");
$address = $telno = $office_no = $job = $email = "";
$email = $_SESSION["email"];
$address = $_REQUEST['address'];
$telno = $_REQUEST['telno'];
$office_no = $_REQUEST['office_no'];
$job = $_REQUEST['job'];
$updateR = "UPDATE public SET address='$address', telno='$telno', office_no='$office_no', job='$job'
WHERE email='$email'";
if(mysqli_query($conn, $updateR)){
echo "<script>";
echo "alert('Butiran anda telah berjaya dikemaskini!');";
echo 'alert ("Insert Success");';
echo 'window.location.href="kk_public.php";' ;
echo "</script>";
}
else{
echo "<script>";
echo "Error updating record: " . mysqli_error($conn);
echo "</script>";
}
mysqli_close($conn);
}
?>
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>BJB — Tempahan</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Free HTML5 Template by FREEHTML5.CO" />
<meta name="keywords" content="free html5, free template, free bootstrap, html5, css3, mobile first, responsive" />
<meta name="author" content="FREEHTML5.CO" />
<!--
//////////////////////////////////////////////////////
FREE HTML5 TEMPLATE
DESIGNED & DEVELOPED by FREEHTML5.CO
Website: http://freehtml5.co/
Email: info@freehtml5.co
Twitter: http://twitter.com/fh5co
Facebook: https://www.facebook.com/fh5co
//////////////////////////////////////////////////////
-->
<!-- Facebook and Twitter integration -->
<meta property="og:title" content=""/>
<meta property="og:image" content=""/>
<meta property="og:url" content=""/>
<meta property="og:site_name" content=""/>
<meta property="og:description" content=""/>
<meta name="twitter:title" content="" />
<meta name="twitter:image" content="" />
<meta name="twitter:url" content="" />
<meta name="twitter:card" content="" />
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="shortcut icon" href="favicon.ico">
<!-- <link href='https://fonts.googleapis.com/css?family=Lato:400,100,100italic,300,300italic,400italic,700italic,900,700,900italic' rel='stylesheet' type='text/css'> -->
<!-- Stylesheets -->
<!-- Dropdown Menu -->
<link rel="stylesheet" href="css/superfish.css">
<!-- Owl Slider -->
<!-- <link rel="stylesheet" href="css/owl.carousel.css"> -->
<!-- <link rel="stylesheet" href="css/owl.theme.default.min.css"> -->
<!-- Date Picker -->
<link rel="stylesheet" href="css/bootstrap-datepicker.min.css">
<!-- CS Select -->
<link rel="stylesheet" href="css/cs-select.css">
<link rel="stylesheet" href="css/cs-skin-border.css">
<!-- Themify Icons -->
<link rel="stylesheet" href="css/themify-icons.css">
<!-- Flat Icon -->
<link rel="stylesheet" href="css/flaticon.css">
<!-- Icomoon -->
<link rel="stylesheet" href="css/icomoon.css">
<!-- Flexslider -->
<link rel="stylesheet" href="css/flexslider.css">
<!-- Style -->
<link rel="stylesheet" href="css/style.css">
<!-- Modernizr JS -->
<script src="js/modernizr-2.6.2.min.js"></script>
<!-- FOR IE9 below -->
<!--[if lt IE 9]>
<script src="js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div id="fh5co-wrapper">
<div id="fh5co-page">
<div id="fh5co-header">
<header id="fh5co-header-section">
<div class="container">
<div class="nav-header">
<a href="#" class="js-fh5co-nav-toggle fh5co-nav-toggle"><i></i></a>
<h1 id="fh5co-logo"><a href="#">Sistem Tempahan BJB</a></h1>
<nav id="fh5co-menu-wrap" role="navigation">
<ul class="sf-menu" id="fh5co-primary-menu">
<li><a class="active" href="portal_public.php">Halaman Utama</a></li>
<li><a href="view_reservation_public.php">Tempahan</a></li>
<li><a href="contactus_user.php">Hubungi Kami</a></li>
<li>
<a href="#" class="fh5co-sub-ddown">Tetapan</a>
<ul class="fh5co-sub-menu">
<li><a href="kk_public.php">Profil</a></li>
<li><a href="logout.php">Log Keluar</a></li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</header>
</div>
<!-- end:fh5co-header -->
<div class="fh5co-parallax" style="background-image: url(images/bluebg.JPG);" data-stellar-background-ratio="0.5">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-md-12 col-md-offset-0 col-sm-12 col-sm-offset-0 col-xs-12 col-xs-offset-0 text-center fh5co-table">
<div class="fh5co-intro fh5co-table-cell">
<img src="images/profile.gif" width="200" height="200" ><br>
Selamat Datang <?php echo $_SESSION["email"]; ?>
<h1 class="text-center">KemasKini Informasi Akaun Pengguna</h1<br><br>
<a href="change_pwd_all.php" target="_blank" id="button">Tukar Kata Laluan</a>
</div>
</div>
</div>
</div>
</div>
<div id="fh5co-services-section">
<div class="container">
<div class="row">
<form>
<?php
include_once("dbconfig.php");
$email = $_SESSION["email"];
$sql="SELECT * FROM profilepic WHERE email='$email'";
$result = mysqli_query($conn, $sql);
$row = $result->fetch_assoc();
?>
<?php echo "<tr><td><img src='" . $row["filepath"] . "'></td>";?><br>
This is your pic ID:<?php echo $row['idpic']; ?><br>
<a href="changePublicProfilePic.php"><label>Kemaskini Gambar Profil</label></a>
<a href="deleteprofilepic.php"><label>Buang Gambar Profil</label></a>
</form>
<form method="POST" action=<?php $_PHP_SELF ?> >
<?php
include_once("dbconfig.php");
$email = $_SESSION["email"];
$sql="SELECT * FROM public WHERE email='$email'";
$result = mysqli_query($conn, $sql);
$row = $result->fetch_assoc();
?>
<label>Nama Pengguna</label>
<input type="text" name="uname" value="<?php echo $row["username"]; ?>" disabled><br>
<label>Nama Sebenar</label>
<input type="text" name="name" value="<?php echo $row['fullname']; ?>" disabled><br>
<label>No. Kad Pengenalan</label>
<input type="text" name="ic" value="<?php echo $row['public_ic']; ?>" disabled><br>
<label>E-mel</label>
<input type="email" name="email" placeholder="cth: abc@gmail.com" value="<?php echo $row['email']; ?>" disabled><br>
<!--Changeable area start from below-->
<label>Tempat Tinggal</label>
<input type="text" name="address" placeholder="Tempat Tinggal" value="<?php echo $row['address']; ?>" required><br>
<label>Tel no.</label>
<input type="text" name="telno" placeholder="0123456789" value="<?php echo $row['telno']; ?>" required><br>
<label>Pekerjaan</label>
<input type="text" name="job" placeholder="pekerjaan" value="<?php echo $row['job']; ?>" required><br>
<!--Not necessary-->
<label>No. Telefon Kerja</label>
<input type="text" name="office_no" value="<?php echo $row['office_no']; ?>" ><br>
<input type="submit" name="submit" value="KemasKini" id="reg_btn">
</div>
</form>
</div>
</div>
</div>
<footer id="footer" class="fh5co-bg-color">
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="copyright">
<p><small>© 2020 Bangsa Johor Bahagia <br> All Rights Reserved. <br>
Designed by <a href="http://freehtml5.co" target="_blank">MemberTech</a> <br> Demo Images: <a href="http://unsplash.com/" target="_blank">Unsplash</a></small></p>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-3">
<h3>Company</h3>
<ul class="link">
<li><a href="#">About Us</a></li>
<li><a href="#">Hotels</a></li>
<li><a href="#">Customer Care</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
<div class="col-md-3">
<h3>Fasiliti Kami</h3>
<ul class="link">
<li><a href="#">Homestay</a></li>
<li><a href="#">Kolong</a></li>
<li><a href="#">Dewan</a></li>
<li><a href="#">Padang</a></li>
<li><a href="#">Gim</a></li>
</ul>
</div>
<div class="col-md-6">
<h3>Subscribe</h3>
<p>Sed cursus ut nibh in semper. Mauris varius et magna in fermentum. </p>
<form action="#" id="form-subscribe">
<div class="form-field">
<input type="email" placeholder="Email Address" id="email">
<input type="submit" id="submit" value="Send">
</div>
</form>
</div>
</div>
</div>
<div class="col-md-3">
<ul class="social-icons">
<li>
<a href="#"><i class="icon-twitter-with-circle"></i></a>
<a href="#"><i class="icon-facebook-with-circle"></i></a>
<a href="#"><i class="icon-instagram-with-circle"></i></a>
<a href="#"><i class="icon-linkedin-with-circle"></i></a>
</li>
</ul>
</div>
</div>
</div>
</footer>
</div>
<!-- END fh5co-page -->
</div>
<!-- END fh5co-wrapper -->
<!-- Javascripts -->
<script src="js/jquery-2.1.4.min.js"></script>
<!-- Dropdown Menu -->
<script src="js/hoverIntent.js"></script>
<script src="js/superfish.js"></script>
<!-- Bootstrap -->
<script src="js/bootstrap.min.js"></script>
<!-- Waypoints -->
<script src="js/jquery.waypoints.min.js"></script>
<!-- Counters -->
<script src="js/jquery.countTo.js"></script>
<!-- Stellar Parallax -->
<script src="js/jquery.stellar.min.js"></script>
<!-- Owl Slider -->
<!-- // <script src="js/owl.carousel.min.js"></script> -->
<!-- Date Picker -->
<script src="js/bootstrap-datepicker.min.js"></script>
<!-- CS Select -->
<script src="js/classie.js"></script>
<script src="js/selectFx.js"></script>
<!-- Flexslider -->
<script src="js/jquery.flexslider-min.js"></script>
<script src="js/custom.js"></script>
</body>
</html>
changePublicProfilePic.php
<?php
include "dbconfig.php";
session_start();
if(!isset($_SESSION["email"])){
echo "<script>";
echo "alert('Anda telah log keluar, sila log masuk semula.');";
echo "location = 'index.php'";
echo "</script>";
}
?>
<?php
if (isset($_REQUEST['submit'])){
$conn= mysqli_connect("localhost","id15455841_members99","sistemBJB-2020","id15455841_adproject2020") or die ("could not connect to mysql");
$email = $_REQUEST['email'];
$target_dir = "images/";
if (is_uploaded_file($_FILES['pic']['tmp_name'])){
$target_file = $target_dir . basename($_FILES["pic"]["name"]);
$filename = basename($_FILES["pic"]["name"]);
}
else{
$target_file = $target_dir . "no-image.png";
$filename = "none";
}
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$sql = mysqli_query($conn, "INSERT INTO profilepic(email, filename, filepath)
VALUES ('$email', '$filename', '$target_file') ");
// Check if image file is a actual image or fake image
if (is_uploaded_file($_FILES['pic']['tmp_name'])) {
$check = getimagesize($_FILES["pic"]["tmp_name"]);
if ($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
}
else {
echo "File is not an image.";
$uploadOk = 0;
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["pic"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0)
echo "Sorry, your file was not uploaded.";
else {
if (move_uploaded_file($_FILES["pic"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["pic"]["name"]). " has been uploaded.";
}
else
echo "Sorry, there was an error uploading your file.";
}
}
if ($sql){
echo "<script>";
echo "alert('Gambar Profil telah berjaya ditambahkan.');";
echo "location='kk_public.php';";
echo "</script>";
}
else{
echo "<script>";
echo "alert('Gagal untuk menambah gambar profil.');";
echo "location = 'changePublicProfilePic.php';";
echo "</script>";
}
mysqli_close($conn);
}
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BJB Tempahan Utiliti</title>
</head>
<body>
<h1>Gambar Profil</h1>
<hr>
<br>
<div>
<form action="<?php $_PHP_SELF ?>" method="POST" enctype="multipart/form-data">
<table class="table-update">
<tr>
<th>Email</th>
<td><input type="text" name="email" size="65" value="<?php echo $_SESSION['email']; ?>"></td>
</tr>
<tr>
<th>Gambar</th>
<td><input type="file" name="pic" id="pic"></td>
</tr>
</table>
<!-- Buttons -->
<div class="button-container">
<div>
<input type="submit" class="update" name="submit" id="button" value="Hantar">
</div>
<div>
<input type="reset" class="reset" id="button" onclick="resett()" value="Set Semula">
</div>
<div>
<a href="kk_public.php">
<input type="button" class="back" id="button" value="Kembali">
</a>
</div>
</div>
<!-- Buttons END -->
</form>
</div>
</body>
</html>
deleteprofilepic.php
<?php
if(isset($_POST['delete'])) {
//Open connection
$conn= mysqli_connect("localhost","id15455841_members99","sistemBJB-2020","id15455841_adproject2020") or die ("could not connect to mysql");
$idpic = $_POST['idpic'];
//Attempt delete query execution
$sql = "DELETE FROM profilepic WHERE idpic= $idpic" ;
//Execute query
if ($conn->query($sql) === TRUE) {
echo "Profile Pic deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
// Close connection
mysqli_close($conn);
}else {
?>
<form method = "post" action = "<?php $_PHP_SELF ?>">
<table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
<tr>
<td width = "100">ID</td>
<td><input name = "idpic" type = "text" id = "idpic"></td>
<td><input name = "delete" type = "submit" id = "delete" value = "Delete"></td>
</tr>
</table>
</form>
<?php
}
?>
<div id="main">
<form action="kk_public.php" align=left>
<button type="submit"> Balik </button>
</form>
0 Comments