 |
|
อยากทราบว่าทำยังไงเมื่อกดปุ่มสีเขียวถึงสามารถทำให้ status เปลี่ยนจาก ค่า 0 เป็น 1 ทั้งใน แสดงผล และ ในฐานข้อมูลตอนนี้
ติดปัญหาอยู่ที่เดียวช่วยด้วยนะคะ ขอบคุณค่ะ
ไฟล์ index.php
Code (PHP)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<p><br></br></p>
<div class="container">
<a href="upload1.php" class="btn btn-primary">Upload</a>
<p><br/></p>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th width="40px">No</th>
<th>File</th>
<th>Status</th>
<th width="170px">Action</th>
</tr>
</thead>
<tbody>
<?php
include "config.php";
if(isset($_GET['id'])){
if(unlink('./uploads/'.$_GET['name'])){
$stmt=$db->prepare("delete from multiupload where id ='".$_GET['id']."'");
if($stmt->execute()) {
echo "<script>location.href='index.php'</script>";
}
}
}
$stmt=$db->prepare ("select * from multiupload order by id asc");
$stmt->execute();
while($row = $stmt ->fetch()){
?>
<tr>
<td><?php echo $row['id']?></td>
<td><?php echo $row['name']?></td>
<td><?php echo $row['status1']?></td>
<td>
<a href="?name=<?php echo $row ['name']?>&id=<?php echo $row['id']?>" class="btn btn-danger">Delete</a>
<a href="save_approve.php?status1=0&id1=<?=$row['status1']; ?>" class="btn btn-success">Approve</a>
</td>
</tr>
<?php
}
?>
</tbody>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
ไฟล์ upload1.php
Code (PHP)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<p><br></br></p>
<div class="container">
<?php
include "config.php";
if(isset($_FILES['sri'])) {
foreach ($_FILES['sri']['name'] as $file => $name) {
$filename= date('Ymd-His',time()).mt_rand().'-'.$name;
try{
if(move_uploaded_file($_FILES['sri']['tmp_name'][$file], 'uploads/'.$filename)){
$stmt=$db->prepare ("insert into multiupload values('',?,'')");
$stmt->bindParam(1,$filename);
$stmt->execute();
}
} catch (Exception $e) {
echo $e;
}
}
}
?>
<form method="post" enctype="multipart/form-data">
<input type="file" name="sri[]" multiple>
<input type="submit" class="btn btn-primary" value="upload">
<a href="index.php" class="btn btn-info">Back</a>
</form>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
ไฟล์ save_approve.php
Code (PHP)
<? session_start();
mysql_select_db("mydatabase");
$status1=$_GET["status1"];
$id=$_GET["id1"];
if($_GET["status1"] == "0" ) {
$korn = "UPDATE multiupload SET status1 = '1' WHERE id = '$id'";
$objQuery = mysql_query($korn);
echo "Save complete";
}
mysql_close();
?>
Tag : PHP, HTML/CSS, JavaScript, jQuery
|
ประวัติการแก้ไข 2016-09-08 23:35:42 2016-09-09 09:07:44 2016-09-09 14:01:02
|
 |
 |
 |
 |
Date :
2016-09-08 23:33:33 |
By :
jeerawan |
View :
2214 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |