บันทึกข้อมูลยังไม่ได้ ช่วยดูโค้ดให้หน่อยค่ะ ......ขอบคุณล่วงหน้า ค่ะ
frmadd.php
<?php
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("invasiondb");
@mysql_query("SET NAMES UTF8");
?>
<!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></title>
<link href="style.css" rel="stylesheet" type="text/css"/>
<script language = "JavaScript">
//**** List Province (Start) ***//
function listtype(SelectValue)
{
frmMain.ddlstyle.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlstyle.options[frmMain.ddlstyle.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM style ORDER BY style_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = "<?=$objResult["type_id"];?>";
strValue = "<?=$objResult["style_id"];?>";
strItem = "<?=$objResult["style_name"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlstyle.options[frmMain.ddlstyle.length]= myOption
}
<?
}
?>
}
function Listbss(SelectValue)
{
frmMain.ddlbss.length = 0
frmMain.ddlline.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlbss.options[frmMain.ddlbss.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM bss ORDER BY bss_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["division_id"];?>;
strValue = "<?=$objResult["bss_id"];?>";
strItem = "<?=$objResult["bss_name"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlbss.options[frmMain.ddlbss.length]= myOption
}
<?
}
?>
}
//**** List Province (End) ***//
//**** List Amphur (Start) ***//
function Listline(SelectValue)
{
frmMain.ddlline.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlline.options[frmMain.ddlline.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM line ORDER BY line_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["bss_id"];?>;
strValue = "<?=$objResult["line_id"];?>";
strItem = "<?=$objResult["line_name"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlline.options[frmMain.ddlline.length]= myOption
}
<?
}
?>
}
</script>
</head>
<body>
<div id="container">
<!-- header -->
<div id="header">
<div id="slogan"></div>
<div id="logo"><a href="index.php">Invasion System</a></div>
</div>
<div id="menu">
<ul>
<li><a href="frmsearch.php">ค้นหาข้อมูล</a></li>
<li><a href="frmadd.php">จัดการข้อมูลสิ่งรุกล้ำ</a></li>
<li><a href="report.php">รายงานสิ่งรุกล้ำ</a></li>
</ul>
</div>
<!--end header -->
<!-- main -->
<div id="main">
<div id="text">
<h1>ข้อมูลสิ่งรุกล้ำ</h1>
<?
include "connect.php";
?>
<form name="frmMain" action="save.php" method="post">
<table width="100%">
<table width="70%">
<tr>
<th height="30" scope="row"><div align="left">ปี : </div></th>
<td align="left">
<?
$strSQL= "SELECT * FROM year";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<select name="year">
<option value="">เลือกปี</option>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["year_id"];?>"><?=$objResult["year_name"];?></option>
<?
}
?>
</select>
</td>
</tr>
<tr>
<th height="30" scope="row"><div align="left">เดือน : </div></th>
<td align="left">
<?
$strSQL= "SELECT * FROM month";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<select name="month">
<option value="">เลือกเดือน</option>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["month_id"];?>"><?=$objResult["month_name"];?></option>
<?
}
?>
</select>
</td>
</tr>
<tr>
<th height="30" scope="row"><div align="left">แผนก : </div></th>
<td align="left">
<select id="ddldivision" name="ddldivision" onChange = "Listbss(this.value)">
<option selected value="">เลือกแผนก</option>
<?
$strSQL = "SELECT * FROM division ORDER BY division_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["division_id"];?>"><?=$objResult["division_name"];?></option>
<?
}
?>
</select>
</td>
</tr>
<tr>
<th height="30" scope="row"><div align="left">บสส.ที่รับผิดชอบ : </div></th>
<td align="left">
<select id="ddlbss" name="ddlbss" style="width:120px" onChange = "Listline(this.value)"></select>
</td>
</tr>
<tr>
<th height="30" scope="row"><div align="left">แนวสาย : </div></th>
<td align="left">
<select id="ddlline" name="ddlline" style="width:200px"></select>
</td>
</tr>
<tr align="right">
<tr>
<th height="30" scope="row"><div align="left">ระหว่างเสาไฟต้นที่ : </div></th>
<td align="left">
<input type= "text" name= "txtpole" id = "txtpole" />
</td>
</tr>
<tr>
<th height="30" scope="row"><div align="left">ประเภทสิ่งรุกล้ำ : </div></th>
<td align="left">
<select id="ddltype" name="ddltype" onChange = "listtype(this.value)">
<option selected value="">เลือกประเภท</option>
<?
$strSQL = "SELECT * FROM type ORDER BY type_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["type_id"];?>"><?=$objResult["type_name"];?></option>
<?
}
?>
</select>
</td>
</tr>
<tr>
<th height="30" scope="row"><div align="left">ลักษณะสิ่งรุกล้ำ : </div></th>
<td align="left">
<select id="ddlstyle" name="ddlstyle" style="width:120px" ></select>
</td>
</tr>
<tr>
<th height="30" scope="row"><div align="left">ความสูง : </div></th>
<td align="left"><input type= "text" name= "txtheight" id = "txtheight" /></td>
</tr>
<tr>
<th height="30" scope="row"><div align="left">ล้ำเขต : </div></th>
<td align="left">
<input type= "text" name= "txtbarrier" id = "txtbarrier" />
</td>
</tr>
<tr>
<th height="30" scope="row"><div align="left">รายละเอียด : </div></th>
<td align="left">
<input type= "text" name= "txtdetail" id = "txtdetail">
</td>
</tr>
<th height="30" scope="row"><div align="left">ตรวจพบเมื่อ : </div></th>
<td align="left">
<input type= "text" name= "txtdetected" id = "txtdetected">
</td>
</tr>
<tr >
<th height="30" scope="row"><div align="left">สถานะ : </div></th>
<td align="left">
<?
$strSQL = "SELECT * FROM status";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<select name="status">
<option value="">เลือกสถานะ</option>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["status_id"];?>"><?=$objResult["status_name"];?></option>
<?
}
?>
</select>
</td>
</tr>
<tr >
<th height="30" scope="row"><div align="left">วันที่ครบกำหนดผ่อนผันตามสถานะ : </div></th>
<td align="left">
<input type= "text" name= "txtdeadline" id = "txtdeadline">
</td>
</tr>
<tr >
<th height="30" scope="row"><div align="left">ชื่อ : </div></th>
<td align="left">
<input name="txtname" type="text" id="txtname" size="30" />
</td>
</tr>
<tr >
<th height="30" scope="row"><div align="left">ที่อยู่ : </div></th>
<td align="left">
<input name="txtaddress" type="text" id="txtaddress" size="30" />
</td>
</tr>
<tr >
<th height="30" scope="row"><div align="left">โทร :</div></th>
<td align="left">
<input type= "text" name= "txttel" id = "txttel" >
</td>
</tr>
</table>
<div align="center">
<input type="submit" name="submit" value="บันทึก">
</table>
</div>
</form>
</div>
</div>
</div>
<!-- end main -->
<!-- footer -->
<div id="footer">
<div id="footer_left">กองบำรุงรักษาระบบสายส่ง</div>
<div id="footer_right">
</div>
</div>
<!-- end footer -->
</div>
</body>
</html>
save.php
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("invasiondb");
mysql_query("SET NAMES UTF8");
$year_id=$_POST['year'];
$month_id=$_POST['month'];
$ddldivision=$_POST['ddldivision'];
$ddlbss=$_POST['ddlbss'];
$ddlline=$_POST['ddlline'];
$pole=$_POST['pole'];
$ddltype=$_POST['ddltype'];
$ddlstyle=$_POST['ddlstyle'];
$height=$_POST['height'];
$barrier=$_POST['barrier'];
$detail=$_POST['detail'];
$detected=$_POST['detected'];
$status=$_POST['status'];
$deadline=$_POST['deadline'];
$name=$_POST['name'];
$address=$_POST['address'];
$tel=$_POST['tel'];
$strSQL="insert into invasion values ('$year_id','$month_id','$ddldivision','$ddlbss','$ddlline','$pole','$ddltype','$ddlstyle','$height',$barrier',$detail',$detected',$status',$deadline',$name',$address',$tel')";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
Tag : PHP, MySQL
ประวัติการแก้ไข 2011-12-19 13:41:09 2011-12-19 13:43:32
Date :
2011-12-19 13:38:45
By :
lookpla26
View :
760
Reply :
2
ตรงนี้นะครับ
Code (PHP)
$strSQL="insert into invasion values ('$year_id','$month_id','$ddldivision','$ddlbss','$ddlline','$pole','$ddltype','$ddlstyle','$height',$barrier',$detail',$detected',$status',$deadline',$name',$address',$tel')";
ต้องเป็น
Code (PHP)
INSERT INTO [Table-Name] (Column1,Column2,Column3,...) VALUES ('Value1','Value2','Value3',...)
ตัวอย่าง
Code (PHP)
INSERT INTO country (CountryCode,CountryName) VALUES ('CH','Chaina')
Date :
2011-12-19 15:46:21
By :
yogolas
Load balance : Server 00