<?php
error_reporting( ~E_NOTICE );
require_once 'dbconfig.php';
if(isset($_GET['edit_id']) && !empty($_GET['edit_id']))
{
$id = $_GET['edit_id'];
$stmt_edit = $DB_con->prepare('SELECT userName, userProfession, userPic FROM tbl_users WHERE userID =:uid');
$stmt_edit->execute(array(':uid'=>$id));
$edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
extract($edit_row);
}
else
{
header("Location: index.php");
}
if(isset($_POST['btn_save_updates']))
{
$username = $_POST['user_name'];// user name
$userjob = $_POST['user_job'];// user email
$imgFile = $_FILES['user_image']['name'];
$tmp_dir = $_FILES['user_image']['tmp_name'];
$imgSize = $_FILES['user_image']['size'];
if($imgFile)
{
$upload_dir = 'user_images/'; // upload directory
$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
$userpic = rand(1000,1000000).".".$imgExt;
if(in_array($imgExt, $valid_extensions))
{
if($imgSize < 5000000)
{
unlink($upload_dir.$edit_row['userPic']);
move_uploaded_file($tmp_dir,$upload_dir.$userpic);
}
else
{
$errMSG = "Sorry, your file is too large it should be less then 5MB";
}
}
else
{
$errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
}
}
else
{
// if no image selected the old image remain as it is.
$userpic = $edit_row['userPic']; // old image from database
}
// if no error occured, continue ....
if(!isset($errMSG))
{
$stmt = $DB_con->prepare('UPDATE tbl_users
SET userName=:uname,
userProfession=:ujob,
userPic=:upic
WHERE userID=:uid');
$stmt->bindParam(':uname',$username);
$stmt->bindParam(':ujob',$userjob);
$stmt->bindParam(':upic',$userpic);
$stmt->bindParam(':uid',$id);
if($stmt->execute()){
?>
<script>
alert('Successfully Updated ...');
window.location.href='index.php';
</script>
<?php
}
else{
$errMSG = "Sorry Data Could Not Updated !";
}
}
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload, Insert, Update, Delete an Image using PHP MySQL - Coding Cage</title>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="bootstrap/css/bootstrap-theme.min.css">
<!-- custom stylesheet -->
<link rel="stylesheet" href="style.css">
<!-- Latest compiled and minified JavaScript -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="jquery-1.11.3-jquery.min.js"></script>
</head>
<body>
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="http://www.codingcage.com" title='Programming Blog'>Coding Cage</a>
<a class="navbar-brand" href="http://www.codingcage.com/search/label/CRUD">CRUD</a>
<a class="navbar-brand" href="http://www.codingcage.com/search/label/PDO">PDO</a>
<a class="navbar-brand" href="http://www.codingcage.com/search/label/jQuery">jQuery</a>
</div>
</div>
</div>
<div class="container">
<div class="page-header">
<h1 class="h2">update profile. <a class="btn btn-default" href="index.php"> all members </a></h1>
</div>
<div class="clearfix"></div>
<form method="post" enctype="multipart/form-data" class="form-horizontal">
<?php
if(isset($errMSG)){
?>
<div class="alert alert-danger">
<span class="glyphicon glyphicon-info-sign"></span> <?php echo $errMSG; ?>
</div>
<?php
}
?>
<table class="table table-bordered table-responsive">
<tr>
<td><label class="control-label">Username.</label></td>
<td><input class="form-control" type="text" name="user_name" value="<?php echo $userName; ?>" required /></td>
</tr>
<tr>
<td><label class="control-label">Profession(Job).</label></td>
<td><input class="form-control" type="text" name="user_job" value="<?php echo $userProfession; ?>" required /></td>
</tr>
<tr>
<td><label class="control-label">Profile Img.</label></td>
<td>
<p><img src="user_images/<?php echo $userPic; ?>" height="150" width="150" /></p>
<input class="input-group" type="file" name="user_image" accept="image/*" />
</td>
</tr>
<tr>
<td colspan="2"><button type="submit" name="btn_save_updates" class="btn btn-default">
<span class="glyphicon glyphicon-save"></span> Update
</button>
<a class="btn btn-default" href="index.php"> <span class="glyphicon glyphicon-backward"></span> cancel </a>
</td>
</tr>
</table>
</form>
<div class="alert alert-info">
<strong>tutorial link !</strong> <a href="http://www.codingcage.com/2016/02/upload-insert-update-delete-image-using.html">Coding Cage</a>!
</div>
</div>
</body>
</html>
没有合适的资源?快使用搜索试试~ 我知道了~
Upload-Insert-Update-Delete-Image-PHP-MySQL.rar_msql
共18个文件
php:4个
css:4个
js:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 199 浏览量
2022-09-23
02:30:21
上传
评论
收藏 268KB RAR 举报
温馨提示
upload insert php crud msql
资源推荐
资源详情
资源评论
收起资源包目录
Upload-Insert-Update-Delete-Image-PHP-MySQL.rar (18个子文件)
Upload-Insert-Update-Delete-Image-PHP-MySQL
bootstrap
css
bootstrap-theme.css 26KB
bootstrap.min.css 118KB
bootstrap.css 143KB
bootstrap-theme.min.css 23KB
fonts
glyphicons-halflings-regular.woff 23KB
glyphicons-halflings-regular.woff2 18KB
glyphicons-halflings-regular.ttf 44KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.svg 106KB
js
npm.js 484B
bootstrap.min.js 36KB
bootstrap.js 67KB
testdb.sql 1KB
index.php 4KB
editform.php 5KB
dbconfig.php 321B
addnew.php 5KB
user_images
432422.jpg 103KB
共 18 条
- 1
资源评论
周楷雯
- 粉丝: 78
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功