รบกวนดูให้ผมที่ครับเรื่องการบันทึก หลังจากแก้ไขแล้ว WHERE ด้วย GET แล้วไม่มีค่ามา
Code (PHP)
<html>
<head>
<title>ระบบจองห้องประชุม สำนักงานจังหวัดลำปาง</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$cs1 = "SET character_set_results=tis620";
mysql_query($cs1) or die('Error query: ' . mysql_error());
$cs2 = "SET character_set_client = tis620";
mysql_query($cs2) or die('Error query: ' . mysql_error());
$cs3 = "SET character_set_connection = tis620";
mysql_query($cs3) or die('Error query: ' . mysql_error());
/*
$d=date('Y-m-d');
echo "$d ";
echo "$_POST[roomddl]";
echo "$_POST[txtdate]";
echo "$_POST[timedll]";
echo "$_POST[namerestxt]";
echo "$_POST[txtunit]";
echo "$d";
*/
$objDB = mysql_select_db("test");
$strSQL = "UPDATE tbres SET ";
$strSQL .="room = '".$_POST["roomddl"]."' ";
$strSQL .=", log_date = CURDATE() ";
//$strSQL .="log_date = .CURDATE(). ";
$strSQL .=",use_date = '".$_POST["txtdate"]."' ";
$strSQL .=",time_res = '".$_POST["timedll"]."' ";
$strSQL .=",res_ing = '".$_POST["namerestxt"]."' ";
$strSQL .=",unit = '".$_POST["txtunit"]."' ";
$strSQL .=" WHERE use_date = '".$_GET["use_date"]."'AND room= '".$_GET["room"]."'AND time_res= '".$_GET["time_res"]."'";
echo "$_GET[use_date]";
echo "$strSQL";
//$objQuery = mysql_query($strSQL);
$objQuery = mysql_query($strSQL) or die(mysql_error());
if($objQuery)
{
echo "";
}
else
{
echo "<script>
alert('บันทึกไม่ได้');
window.location='list_admin.php';
</script>";
exit();
}
mysql_close($objConnect);
?>
</body>
</html>
ผมลอง echo $strSQL ดูแล้วครับ ได้มาแบบนี้
UPDATE tbres SET room = '3' , log_date = CURDATE() ,use_date = '2009-10-25' ,time_res = '3' ,res_ing = '' ,unit = 'กลุ่มงานข้อมูลฯ' WHERE use_date = ''AND room= ''AND time_res= ''Tag : - - - -
Date :
2009-09-24 10:05:27
By :
oasiis
View :
853
Reply :
3
แล้วมันส่งมายังไงครับ
Date :
2009-09-24 10:19:09
By :
reda_008
Page "Edit.php"
Code (PHP)
<?php
<?
/*session_start();
include "check.php";*/
include "conn.php";
?>
<!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=windows-874" />
<title>ระบบจองห้องประชุม สำนักงานจังหวัดลำปาง</title>
<link rel="stylesheet" type="text/css" href="epoch_styles.css" />
<script type="text/javascript" src="epoch_classes.js"></script>
<script type="text/javascript">
var bas_cal,dp_cal,ms_cal;
window.onload = function () {
dp_cal = new Epoch('epoch_popup','popup',document.getElementById('popup_container'));
};
</script>
<script language="javascript" type="text/javascript">
function LogoutSystem() //ประยุกใช้เอาตามสถานการณ์นะครับ
{
parent.location.replace("login.html"); //คำสั่งที่ให้ไปยังเพจอื่นเมื่อถึงเวลาที่กำหนด ใช้แพแรนท์ตามด้วยชื่อเฟรม หากไม่มีเฟรมก็ตัดทิ้งไป แล้วทามด้วยโลเคชั่น ตามด้วยรีเพลค สาเหตุที่ใช้รีเพลคเพราะไม่ต้องการให้สามารถกดปุ่มย้อนกลับได้
}
var timer1;
function Ehandler()
{
clearTimeout(timer1);
timer1 = setTimeout("LogoutSystem()", 1000*60*10);
return true;
}
Ehandler();
if(!document.all){window.captureEvents(Event.CLICK | Event.KEYPRESS);}
window.onclick = Ehandler;
window.onkeypress = Ehandler;
</script>
<style type="text/css">
<!--
body,td,th {
font-family: MS Reference Sans Serif;
}
a {
font-family: MS Reference Sans Serif;
}
h1,h2,h3,h4,h5,h6 {
font-family: MS Reference Sans Serif;
}
.style1 {color: #990000}
.style2 {
color: #CC3300;
font-size: 14px;
}
.style3 {font-size: 14px}
-->
</style></head>
<body onclick="Ehandler()" onkeypress="Ehandler()">
<table width="650" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center">
<table width="650" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="pic/head03.gif" width="650" height="80" border="0" /></td>
</tr>
<tr>
<td valign="middle"><table width="650" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="290" align="left" valign="middle"><span class="style1"><span class="style3"><img src="pic/2.gif" width="20" height="29" border="0" align="absmiddle" />
<?
if ($_SESSION['level']=="1")$_SESSION['level']="ผู้ดูแลระบบ";
if ($_SESSION['level']=="2")$_SESSION['level']="ผู้ใช้ทั่วไป";
echo $_SESSION['level'];?>
</span> : <span class="style2"><?echo $_SESSION['units'];?></span></span></td>
<td width="360" height="33" align="right" valign="middle"><a href="index.php"><img src="pic/home.gif" alt="กลับสู่หน้าหลัก" width="88" height="30" border="0" align="absmiddle" /></a> <a href="logout.php"><img src="pic/logout.gif" alt="ออกจากระบบ" width="122" height="30" border="0" align="absmiddle" /></a> </td>
</tr>
</table></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="400" background="body.gif"><table width="650" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="400" background="pic/body.gif"><table width="650" height="400" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="400" valign="top" background="pic/book05.gif">
<table width="650" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25" align="right" valign="bottom"><span class="style3">วันที่
<?include "date.php";?>
</span></td>
</tr>
<tr>
<td height="20" valign="top"> </td>
</tr>
</table>
<?
$SQL = "SELECT * FROM tbres WHERE use_date = '".$_GET["use_date"]."'AND room= '".$_GET["room"]."'AND time_res= '".$_GET["time_res"]."'";
$obj = mysql_query($SQL);
$objResult = mysql_fetch_array($obj);
if(!$objResult)
{
echo "ไม่พบข้อมูล";
}
else
{
$room=$objResult["room"];
$log=$objResult["log_date"];
$use_date=$objResult["use_date"];
$time_res=$objResult["time_res"];
$res_ing=$objResult["res_ing"];
$unt=$objResult["unit"];
?>
<table width="650" height="285" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="20"> </td>
<td height="20"> </td>
<td height="20"> </td>
<td height="20"> </td>
</tr>
<FORM METHOD=POST ACTION="save.php">
<tr>
<td height="25"> </td>
<td height="25"><div align="right">ห้องประชุม : </div></td>
<td height="25"><div align="left">
<select name="roomddl" size="1" id="roomddl">
<option>-- เลือกห้องประชุม --</option>
<option value="1">ห้องประชุม 1</option>
<option value="2">ห้องประชุม 2</option>
<option value="3">ห้อง POC</option>
</select>
</div></td>
<td height="25"> </td>
</tr>
<tr>
<td width="82" height="25"> </td>
<td width="249" height="25"><div align="right">วันที่ต้องการจอง : </div></td>
<td width="249" height="25"><div align="left">
<input name="txtdate" id="popup_container" type="date" size="10"/>
</div></td>
<td width="70" height="25"> </td>
</tr>
<tr>
<td height="25"> </td>
<td height="25"><div align="right">ช่วงเวลา : </div></td>
<td height="25"><div align="left">
<select name="timedll" id="timedll">
<option>--เลือกช่วงเวลา --</option>
<option value="1">เช้า</option>
<option value="2">บ่าย</option>
<option value="3">เช้า - บ่าย</option>
</select>
</div></td>
<td height="25"> </td>
</tr>
<tr>
<td height="25"> </td>
<td height="25"><div align="right">ชื่อผู้จอง : </div></td>
<td height="25"><div align="left">
<input name="namerestxt" type="text" size="30" value="<?=$res_ing;?>" readonly/>
</div></td>
<td height="25"> </td>
</tr>
<tr>
<td height="25"> </td>
<td height="25"><div align="right">หน่วยงาน: </div></td>
<td height="25"><div align="left"> <INPUT NAME="txtunit" TYPE="text" value="<?=$unt;?>" size="18" readonly >
</div></td>
<td height="25"> </td>
</tr>
<tr>
<td height="105"> </td>
<td height="105"> </td>
<td height="105"><div align="right">
<input type="submit" value="แก้ไข" />
<img src="pic/ok.gif" width="67" height="101" border="0" align="bottom"/></div></td>
<td height="105"> </td>
</tr>
<?}?>
</FORM>
</table>
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td valign="middle"> </td>
</tr>
<tr>
<td><div align="center"><img src="pic/foot.gif" width="650" height="70" border="0" /></div></td>
</tr>
</table>
</body>
</html>
?>
Page "save.php"
Code (PHP)
<?php
<html>
<head>
<title>ระบบจองห้องประชุม สำนักงานจังหวัดลำปาง</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$cs1 = "SET character_set_results=tis620";
mysql_query($cs1) or die('Error query: ' . mysql_error());
$cs2 = "SET character_set_client = tis620";
mysql_query($cs2) or die('Error query: ' . mysql_error());
$cs3 = "SET character_set_connection = tis620";
mysql_query($cs3) or die('Error query: ' . mysql_error());
/*
$d=date('Y-m-d');
echo "$d ";
echo "$_POST[roomddl]";
echo "$_POST[txtdate]";
echo "$_POST[timedll]";
echo "$_POST[namerestxt]";
echo "$_POST[txtunit]";
echo "$d";
*/
$objDB = mysql_select_db("test");
$strSQL = "UPDATE tbres SET ";
$strSQL .="room = '".$_POST["roomddl"]."' ";
$strSQL .=", log_date = CURDATE() ";
//$strSQL .="log_date = .CURDATE(). ";
$strSQL .=",use_date = '".$_POST["txtdate"]."' ";
$strSQL .=",time_res = '".$_POST["timedll"]."' ";
$strSQL .=",res_ing = '".$_POST["namerestxt"]."' ";
$strSQL .=",unit = '".$_POST["txtunit"]."' ";
$strSQL .=" WHERE use_date = '".$_GET["use_date"]."'AND room= '".$_GET["room"]."'AND time_res= '".$_GET["time_res"]."'";
echo "$_GET[use_date]";
//$objQuery = mysql_query($strSQL);
$objQuery = mysql_query($strSQL) or die(mysql_error());
if($objQuery)
{
echo "$strSQL";
}
else
{
echo "<script>
alert('บันทึกไม่ได้');
window.location='list_admin.php';
</script>";
exit();
}
mysql_close($objConnect);
?>
</body>
</html>
?>
Date :
2009-09-24 10:28:15
By :
oasiis
คุณครับคุณส่งมาเฉพาะแบบ POST แล้วจะรับแบบ GET ด้วย แล้ว condition หลัง where คุณระบุ รับมาแบบ GET ในความเป็นจริง คุณไม่ได้ส่งค่า อะไรมาทาง GET เลยนะครับ หลังจากที่คุณกด submit form ส่งมาแล้ว มันก็จะวิ่งตาม action='save.php' วิ่งไปตาม method = "POST" เท่านั้น
ฉะนั้นคุณต้องแก้ไขโดย
จะส่งค่า param ตาม action ให้มาแบบ get ด้วย โดยระบุ
action='save.php?time_res=xxx¶m2=xxx' โดยยังคง method ให้เป็นแบบ post เหมือนเดิมจะได้ไม่มีผลต่อ การรับค่าของคุณกับตัวแปร อื่นๆ
แต่ผมแนะนำนะครับ ส่งค่าไปแบบ post ทั้งหมดจะดีกว่าครับ โดย time_res และตัวอื่นๆ ที่ไม่ต้องแสดง
บน url
ก็ให้ใส่ใน text from โดย ระบุ type='hidden' ไว้ แล้ว ต้อนรับไฟล์ใน save.php ให้เปลี่ยนจาก
$_GET["use_date"] ให้เป็น $_post ทั้งหมดครับ จะได้ไม่งง แถม จะได้ secure มาในระดับหนึ่งด้วย
Date :
2009-09-24 17:17:16
By :
joekung
Load balance : Server 00