|
|
|
สอบถามการ insert ข้อมูลได้ที่จาก Checkbox หลาย ๆ ค่าไปเก็บใน DB field เดียว |
|
|
|
|
|
|
|
ต้องการจะ insert ข้อมูลที่ได้จาก checkbox หลายๆ ค่า ลง field เดียวกัน ต้องทำอย่างไรคะ ตอนนี้ใน DB ขึ้นว่า Array
INSERT
<?php
require_once('../config.php');
if($_POST["txt_id"] == ""){
$strSQL = " INSERT INTO tb_ps ";
$strSQL .= "(`PS_date`,`PS_sot`,`PS_sale`,`PS_job`,`PS_qt`,`PS_sc`,`PS_as`,`PS_re`) ";
$strSQL .= "VALUES ";
$strSQL .= "('".$_POST["txt_date"]."','".$_POST["txt_sot"]."','".$_POST["txt_sale"]."','".$_POST["txt_job"]."','".$_POST["txt_qua"]."','".$_POST["txt_sent_to_cus"]."','".$_POST["txt_assign"]."','".$_POST["txt_remar"]."') ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "<script language=\"JavaScript\">alert(\"บันทึกเรียบร้อย\");</script>";
echo "<script language=\"JavaScript\">window.location.href = \"proser.php\";</script>";
}
else
{
echo "<script language=\"JavaScript\">alert(\"บันทึกไม่สำเร็จ\");</script>";
echo "<script language=\"JavaScript\">window.location.href = \"proser.php\";</script>";
}
}else{
$strSQL = " UPDATE tb_ps SET ";
$strSQL .= "`PS_date`='".$_POST["txt_date"]."',`PS_sot`='".$_POST["txt_sot"]."',`PS_sale`='".$_POST["txt_sale"]."',`PS_job`='".$_POST["txt_job"]."',`PS_qt`='".$_POST["txt_qua"]."',`PS_sc`='".$_POST["txt_sent_to_cus"]."',`PS_as`='".$_POST["txt_assign"]."',`PS_re`='".$_POST["txt_remar"]."' ";
$strSQL .= "WHERE `PS_id`='".$_POST["txt_id"]."' ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "<script language=\"JavaScript\">alert(\"แก้ไขเรียบร้อย\");</script>";
echo "<script language=\"JavaScript\">window.location.href = \"proser.php\";</script>";
}
else
{
echo "<script language=\"JavaScript\">alert(\"แก้ไขไม่สำเร็จ\");</script>";
echo "<script language=\"JavaScript\">window.location.href = \"proser.php\";</script>";
}
}
mysql_close($objConnect);
?>
FORM
<?php
session_start();
include "../config.php";
if($_SESSION['Id'] == "")
{
//echo "กรุณา Login ก่อนเข้าใช้งานระบบ";
echo "<meta http-equiv='refresh' content='1;URL=../index.html' />";
exit();
}else if($_SESSION['Status'] != "ADMIN")
{
//echo "ผู้ใช้ท่านอื่นที่ไม่ใช้พนักงานไม่สามารถใช้ฟังข์ขันนี้ได้";
echo "<meta http-equiv='refresh' content='1;URL=../index.html' />";
exit();
}else{
$strSQL = "SELECT * FROM tb_user WHERE Id = '".$_SESSION['Id']."'";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
$strSQL2 = "SELECT * FROM tb_ps ORDER BY ps_date DESC ";
$objQuery2 = mysql_query($strSQL2);
if(isset($_GET['id'])){
$strSQL3 = "SELECT * FROM tb_ps WHERE PS_id = '".$_GET['id']."' ";
$objQuery3 = mysql_query($strSQL3);
$objResult3 = mysql_fetch_array($objQuery3);
}
if($_GET['txtkeyword'] != ""){
$strSQL2 = "SELECT * FROM tb_ps WHERE PS_sale LIKE '%".$_GET['txtkeyword']."%' ";
$objQuery2 = mysql_query($strSQL2);
}else{
$strSQL2 = "SELECT * FROM tb_ps ORDER BY PS_date DESC ";
$objQuery2 = mysql_query($strSQL2);
}
}
?>
<!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">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../img/ERT.png">
<title>Professional Service Support</title>
<!-- Bootstrap core CSS -->
<link href="../dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/starter-template.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="../assets/js/ie-emulation-modes-warning.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../assets/js/ie10-viewport-bug-workaround.js"></script>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Custom styles for this template -->
<link href="css/carousel.css" rel="stylesheet" type="text/css">
</head>
<script>
function refreshPage() {
window.location = "proser.php";
}
</script>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- ชื่อโปรแกรม -->
<a class="navbar-brand" href="home.php">ASSW@ERT</a>
</div>
<!-- เมนูด้านบน -->
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="proser.php">Professional Service Support</a></li>
<li><a href="cussup.php">Customer Support</a></li>
<li><a href="reser.php">Repair Service</a></li>
<!--<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Room Daily Report<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">-->
<li><a href="roomdai-hq.php">Room Daily Report</a></li>
<!--<li><a href="roomdai-sl.php">SL</a></li>
<li><a href="roomdai-sv.php">SV</a></li>
</ul>-->
<li><a href="about.php">About</a></li>
<li><a href="../logout.php">Logout</a></li>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container">
<div class="starter-template">
<img class="img-circle" src="../img/L4.png" alt="Generic placeholder image" style="width: 140px; height: 140px;">
<h1>Professional Service Support</h1>
<br />
<form class="form-horizontal" role="form" action="fn_proser.php" method="post">
<div class="form-group">
<label for="txt_date" class="col-sm-4 control-label">Date</label>
<div class="col-sm-4">
<input type="hidden" name="txt_id" value="<?=$_GET['id']?>">
<input type="date" name="txt_date" class="form-control" id="txt_date" required value="<?=$objResult3[1]?>">
</div>
</div>
<div class="form-group">
<label for="txt_sot" class="col-sm-4 control-label">ชื่อ</label>
<div class="col-sm-4">
<input type="text" name="txt_sot" class="form-control" id="txt_sot" placeholder="" required value="<?=$objResult3[2]?>">
</div>
</div>
<div class="form-group">
<label for="txt_sale" class="col-sm-4 control-label">เบอร์โทรศัพท์</label>
<div class="col-sm-4">
<input type="text" name="txt_sale" class="form-control" id="txt_sale" placeholder="" required value="<?=$objResult3[3]?>">
</div>
</div>
<div class="form-group">
<label for="txt_job" class="col-sm-4 control-label">Job</label>
<div class="col-sm-4">
<input type="checkbox" name="txt_job[]" value="Red">Red
<input type="checkbox" name="txt_job[]" value="blue">blue
<input type="checkbox" name="txt_job[]" value="green">green<br>
<?=$objResult3[4]?>
</div>
</div>
<div class="form-group">
<label for="txt_qua" class="col-sm-4 control-label">Quantity (Unit)</label>
<div class="col-sm-4">
<input type="number" name="txt_qua" class="form-control" id="txt_qua" placeholder="*จำนวนสินค้า" required value="<?=$objResult3[5]?>">
</div>
</div>
<div class="form-group">
<label for="txt_sent_to_cus" class="col-sm-4 control-label">Sent to Customer</label>
<div class="col-sm-4">
<input type="date" name="txt_sent_to_cus" class="form-control" id="txt_sent_to_cus" placeholder="" required value="<?=$objResult3[6]?>">
</div>
</div>
<div class="form-group">
<label for="txt_assign" class="col-sm-4 control-label">Assign to</label>
<div class="col-sm-4">
<input type="text" name="txt_assign" class="form-control" id="txt_assign" placeholder="" required value="<?=$objResult3[7]?>">
</div>
</div>
<div class="form-group">
<label for="txt_remar" class="col-sm-4 control-label">Remark</label>
<div class="col-sm-4">
<textarea class="form-control" name="txt_remar" id="txt_remar" rows="3" placeholder="*ห้ามเว้นที่ว่าง" required><?=$objResult3[8]?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-4">
<button type="submit" class="btn btn-success">Save</button>
<button type="reset" onclick="refreshPage();" class="btn btn-info">Reset</button>
</div>
</div>
</form>
<br>
<form class="navbar-form navbar-center" role="search" action="proser.php" method="get">
<div class="form-group"></div>
<span class="form-group">
<input type="text" id="txtkeyword" name="txtkeyword" class="form-control" placeholder="Search from Sale" required>
</span>
<button type="submit" value="Search" class="btn btn-success"> Submit </button>
</form>
</div> <!-- End starter-template -->
<!-- แถบเลื่อน SCROLLBAR ขึ้น-ลง -->
<div style="width: auto; height: 200px; overflow-y: scroll; scrollbar-arrow-color:blue; scrollbar-face-color: #e7e7e7; scrollbar-3dlight-color: #a0a0a0; scrollbar-darkshadow-color:#888888">
<p align="center">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>NO.</th>
<th>Date</th>
<th>SOT NO.</th>
<th>Sale</th>
<th>Job</th>
<th>Quantity(Unit)</th>
<th>Sent to Customer</th>
<th>Assign To</th>
<th>Remark</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
</p>
<?php
$count = 1;
while($objResult2 = mysql_fetch_array($objQuery2)){
echo "<tr>
<td>$count</td>
<td>$objResult2[1]</td>
<td>$objResult2[2]</td>
<td>$objResult2[3]</td>
<td>$objResult2[4]</td>
<td>$objResult2[5]</td>
<td>$objResult2[6]</td>
<td>$objResult2[7]</td>
<td>$objResult2[8]</td>
<td><button onclick=\"window.location.href='proser.php?id=$objResult2[0]'\">Edit</button></td>
<td><button onclick=\"window.location.href='fn_del_proser.php?id=$objResult2[0]'\">Del</button></td>
</tr>";
$count++;
}
?>
</tbody>
</table>
</div>
</div><!-- /.container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="../dist/js/bootstrap.min.js"></script>
</body>
</html>
<?php mysql_close($objConnect); ?>
Tag : PHP, MySQL, HTML/CSS
|
ประวัติการแก้ไข 2016-06-01 12:12:22
|
|
|
|
|
Date :
2016-06-01 12:01:47 |
By :
mintjin |
View :
1138 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ได้ดูโค๊ดนะ ถ้ามันขึ้นเป็น array ปกติเราจะต้อง ใส่ index ให้กับ array เข้าไป โดยการวนลูป หรือระบุค่าลงไปในนั้นเลย เช่น
for($i=0;$i<count($array);$i++){
array[$i]
}
หรือระบุ index ไปตรงๆ แล้วแต่กรณี
array[0]
array[1]
array[2]
ประมาณนี้ครับ
|
|
|
|
|
Date :
2016-06-01 15:03:00 |
By :
Dragons_first |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|