|
![](/images/resource/spacer.gif) |
|
เพิ่มข้อมูลในหน้าเดียวกันลงฐานข้อมูลแต่เพิ่มไม่ได้ครับ |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
พอดีผมจะเพิ่มข้อมูลในหน้าเดียวกันลงฐานข้อมูลแต่เพิ่มไม่ได้ครับ
เรียนผู้รู้ช่วยดูโค้ดให้หน่อยครับ
ปล.เกี่ยวกับวันที่เพิ่มลงแล้วมันส่งค่าเป็น 0000-00-00 ช่วยดูด้วยนะครับ
<!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>Untitled Document</title>
<style type="text/css">
<!--
body,td,th {
font-family: mS Sans Serif, Tahoma;
font-size: 16px;
}
a {
font-family: mS Sans Serif, Tahoma;
font-size: 14px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
</head>
<body>
<script type="text/javascript" src="user_function/popcalendar.js"></script>
<script language="JavaScript">
function checkFields() {
missinginfo = "";
if (document.form_adddurable.Dur_id.value == "") {
missinginfo += "\n - * หมายเลขคุรุภัณฑ์";
}
if (document.form_adddurable.Equnitkupun_id.value == "") {
missinginfo += "\n - * หน่วยนับครุภัณฑ์";
}
if (document.form_adddurable.Durtype_id.value == "") {
missinginfo += "\n - * ประเภทครุภัณฑ์";
}
if (document.form_adddurable.Attainment_id.value == "") {
missinginfo += "\n - * วิธีการได้มา";
}
if (document.form_adddurable.Status_id.value == "") {
missinginfo += "\n - * สถานะครุภัณฑ์";
}
if (document.form_adddurable.Dep_id.value == "") {
missinginfo += "\n - * แผนกที่รับผิดชอบ";
}
if (document.form_adddurable.Provider_id.value == "") {
missinginfo += "\n - * ชื่อบริษัท";
}
if (document.form_adddurable.Dur_num.value == "") {
missinginfo += "\n - * จำนวนครุภัณฑ์";
}
if (document.form_adddurable.Dur_datewarity.value == "") {
missinginfo += "\n - * วันที่หมดประกัน";
}
if (document.form_adddurable.Dur_dateincome.value == "") {
missinginfo += "\n - * วันเดือนปีที่รับเข้า";
}
if (document.form_adddurable.Dur_price.value == "") {
missinginfo += "\n - * ราคาครุภัณฑ์";
}
if (document.form_adddurable.Dur_Brand.value == "") {
missinginfo += "\n - * ยี่ห้อ";
}
if (document.form_adddurable.Dur_model.value == "") {
missinginfo += "\n - * รุ่น";
}
if (document.form_adddurable.Dur_Fiscalyear.value == "") {
missinginfo += "\n - * ปีงบประมาณ";
}
if (document.form_adddurable.Dur_SerialNumber.value == "") {
missinginfo += "\n - * Serial Number";
}
if (document.form_adddurable.Dur_name.value == "") {
missinginfo += "\n - * รายการครุภัณฑ์";
}
if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"คุณยังไม่ได้กรอกข้อมูลในช่อง " +
missinginfo + "\n_____________________________" +
"\nกรุณากลับไปกรอกอีกครั้ง ";
alert(missinginfo);
return false;
}
else return true;
}
</script>
<script language="JavaScript" type="text/JavaScript">
function check_key_number() {
use_key=event.keyCode
if (use_key != 13 && (use_key < 48) || (use_key > 57)) {
alert('กรุณากรอกข้อมูลเป็นตัวเลข 0-9 ');
event.returnValue = false;
}
}
</script>
<?
$pic_boolean = null;
$File_Images= "File_Images/";
$pic = $_FILES['pic']['name'];
if ($_FILES['pic']['tmp_name'] != "") // ตรวจสอบว่ามีไฟล์ส่งมาหรือไม่
{
if(strchr($_FILES['pic']['name'],".")==".JPG" || strchr($_FILES['pic']['name'],".")==".jpg" || strchr($_FILES['pic']['name'],".")==".GIF" || strchr($_FILES['pic']['name'],".")==".gift")
{
copy($_FILES['pic']['tmp_name'],"$File_Images/$pic"); // Copy File ไว้ที่ Folder File
$pic_boolean = true;
echo "";
//echo "pic===true";
}else{
echo "ไฟล์ที่ส่งมาไม่ใช่ไฟล์ .Gif และ .Jpg";
$pic_boolean = false;
echo "file===false";
}
}
if($pic_boolean == true ){
include('Connection/Conndb.php');
$Dur_id = $_POST[Dur_id];
$Equnitkupun_id=$_POST[Equnitkupun_id];
$Durtype_id=$_POST[Durtype_id];
$Attainment_id=$_POST[Attainment_id];
$Status_id=$_POST[Status_id];
$Provider_id=$_POST[Provider_id];
$Dur_num=$_POST[Dur_num];
$Dep_id=$_POST[Dep_id];
$Dur_datewarity=$_POST[Dur_datewarity];
$Dur_dateincome=$_POST[Dur_dateincome];
$Dur_price=$_POST[Dur_price];
$Dur_Brand=$_POST[Dur_Brand];
$Dur_model=$_POST[Dur_model];
$Dur_Fiscalyear=$_POST[Dur_Fiscalyear];
$Dur_SerialNumber=$_POST[Dur_SerialNumber];
$Dur_name=$_POST[Dur_name];
$File_Images = $File_Images.$pic;
$sql="insert into durable (Dur_id, Equnitkupun_id, Durtype_id, Attainment_id, Status_id, Provider_id, Dur_num, Dep_id, Dur_datewarity, Dur_dateincome, Dur_price, Dur_Brand, Dur_model, Dur_Fiscalyear, Dur_SerialNumber, Dur_name, pic) values ('$Dur_id', '$Equnitkupun_id', '$Durtype_id', '$Attainment_id', '$Status_id, '$Provider_id', '$Dur_num', '$Dep_id', '$Dur_datewarity', '$Dur_dateincome', '$Dur_price', '$Dur_Brand', '$Dur_model', '$Dur_Fiscalyear', '$Dur_SerialNumber', '$Dur_name', '$File_Images')";
$result = mysql_db_query($database_conndb,$sql);
if ($result) {
echo "<script>alert('ระบบบันทึกข้อมูล รหัส $_POST[Dur_id] เรียบร้อยแล้ว');window.location='form_durable.php?question_id=$question_id';</script>";
}
mysql_close();
}
else {
echo "<script>alert('ระบบผิดพลาด ไม่สามารถบันทึกข้อมูลนี้ได้ในขณะนี้');</script>";
}
?>
<form id="form_adddurable" name="form_adddurable" method="post" action="form_durable.php" onsubmit="checkFields()">
<table width="62%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF">
<tr>
<td colspan="2" align="center" valign="top" bgcolor="#FF6600"><strong>เพิ่มรายการคุรุภัณฑ์</strong></td>
</tr>
<tr>
<td width="18%" align="right" valign="top" bgcolor="#FFFF99">หมายเลขคุรุภัณฑ์</td>
<td width="82%" align="left" valign="top" bgcolor="#FFFF99"><input type="text" name="Dur_id" id="Dur_id" /></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFF99">รายการคุรุภัณฑ์</td>
<td align="left" valign="top" bgcolor="#FFFF99"><input type="text" name="Dur_name" id="Dur_name" /></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFF99">Serial Number</td>
<td align="left" valign="top" bgcolor="#FFFF99"><input type="text" name="Dur_SerialNumber" id="Dur_SerialNumber" /></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFF99">ชื่อบริบัท</td>
<td align="left" valign="top" bgcolor="#FFFF99"><select name="Provider_id" id="Provider_id" >
<option value="0" selected="selected">-----------------เลือก------------------</option>
<?
require_once('Connection/Conndb.php');
$sql = "SELECT * from provider order by Provider_id";
$result = mysql_query($sql);
while($row=mysql_fetch_assoc($result))
{
?>
<option value="<?=$row['Provider_id'];?>"> <? echo $row['Provider_id']." - ".$row['Provider_name'];?> </option>
<?
}
?>
</select></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFF99">ประเภทคุรุภัณฑ์</td>
<td align="left" valign="top" bgcolor="#FFFF99"><select name="Durtype_id" id="Durtype_id">
<option value="0" selected="selected">------------เลือก-------------</option>
<?
require_once('Connection/Conndb.php');
$sql = "SELECT * from durabletype order by Durtype_id";
$result = mysql_query($sql);
while($row=mysql_fetch_assoc($result))
{
?>
<option value="<?=$row['Durtype_id'];?>"> <? echo $row['Durtype_id']." - ".$row['Durtype_name'];?> </option>
<?
}
?>
</select>
ยี่ห้อ
<label>
<input type="text" name="Dur_Brand" id="Dur_Brand" />
</label>
รุ่น
<input name="Dur_model" type="text" id="Dur_model" /></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFF99">จำนวน</td>
<td align="left" valign="top" bgcolor="#FFFF99"><input type="text" name="Dur_num" id="Dur_num" onKeyPress="check_key_number()"/>
หน่วยนับ
<select name="Equnitkupun_id" id="Equnitkupun_id">
<option value="0" selected="selected">---เลือก---</option>
<?
require_once('Connection/Conndb.php');
$sql = "SELECT * from Equnitku order by Equnitkupun_id";
$result = mysql_query($sql);
while($row=mysql_fetch_assoc($result))
{
?>
<option value="<?=$row['Equnitkupun_id'];?>"> <? echo $row['Equnitkupun_id']." - ".$row['Equnitkupun_name'];?> </option>
<?
}
?>
</select>
ราคา
<input type="text" name="Dur_price" id="Dur_price" onKeyPress="check_key_number()" />
บาท</td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFF99">วิธีการได้มา</td>
<td align="left" valign="top" bgcolor="#FFFF99"><select name="Attainment_id" id="Attainment_id">
<option value="0" selected="selected">------------เลือก-------------</option>
<?
require_once('Connection/Conndb.php');
$sql = "SELECT * from attainment order by Attainment_id";
$result = mysql_query($sql);
while($row=mysql_fetch_assoc($result))
{
?>
<option value="<?=$row['Attainment_id'];?>"> <? echo $row['Attainment_id']." - ".$row['Attainment_name'];?> </option>
<?
}
?>
</select>
ปีงบประมาณ
<input name="Dur_Fiscalyear" type="text" id="Dur_Fiscalyear" maxlength="4" onKeyPress="check_key_number()"/></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFF99">วัน/เดือน/ปีที่รับเข้า</td>
<td align="left" valign="top" bgcolor="#FFFF99"><input type="text" name="Dur_dateincome" id="Dur_dateincome" onKeyPress="Check_Text()" value="<? $today = date("d/m/Y");
list($today, $tomonth, $toyear) = split('[/.-]', $today);
$toyear = $toyear + 543;
echo "$today/$tomonth/$toyear"; ?>" size="10" maxlength="10" />
<script language='javascript'><!--
if (!document.layers) {
document.write("<input type=button onclick='popUpCalendar(this, form_adddurable.Dur_dateincome, \"dd/mm/yyyy\")' value=' Date' style='font-size:11px'>")
} //-->
</script></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFF99">วันที่หมดประกัน</td>
<td align="left" valign="top" bgcolor="#FFFF99"><input type="text" name="Dur_datewarity" id="Dur_datewarity" onKeyPress="Check_Text()" value="<? $today = date("d/m/Y");
list($today, $tomonth, $toyear) = split('[/.-]', $today);
$toyear = $toyear + 543;
echo "$today/$tomonth/$toyear"; ?>" size="10" maxlength="10" />
<script language='javascript'><!--
if (!document.layers) {
document.write("<input type=button onclick='popUpCalendar(this, form_adddurable.Dur_dateincome, \"dd/mm/yyyy\")' value=' Date' style='font-size:11px'>")
} //-->
</script></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFF99">สถานที่จัดเก็บ</td>
<td align="left" valign="top" bgcolor="#FFFF99"><select name="Dep_id" id="Dep_id">
<option value="0" selected="selected">------------เลือก-------------</option>
<?
require_once('Connection/Conndb.php');
$sql = "SELECT * from department order by Dep_id";
$result = mysql_query($sql);
while($row=mysql_fetch_assoc($result))
{
?>
<option value="<?=$row['Dep_id'];?>"> <? echo $row['Dep_id']." - ".$row['Dep_name'];?> </option>
<?
}
?>
</select>
สถานะ
<select name="Status_id" id="Status_id">
<option value="0" selected="selected">----เลือก----</option>
<?
require_once('Connection/Conndb.php');
$sql = "SELECT * from Status order by Status_id";
$result = mysql_query($sql);
while($row=mysql_fetch_assoc($result))
{
?>
<option value="<?=$row['Status_id'];?>"> <? echo $row['Status_id']." - ".$row['Status_name'];?> </option>
<?
}
?>
</select></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFF99">รูปภาพประกอบ</td>
<td align="left" valign="top" bgcolor="#FFFF99"><input type="file" name="pic" id="pic" /></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFF99"> </td>
<td align="left" valign="top" bgcolor="#FFFF99"><input type="submit" name="Submit" id="Submit" value="บันทึก" />
<input type="reset" name="Reset" id="Reset" value="ยกเลิก" /></td>
</tr>
</table>
</form>
</body>
</html>
Tag : - - - -
![](/images/adv.jpg?v=1001)
|
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2010-05-30 17:21:20 |
By :
HaKonNan |
View :
1008 |
Reply :
3 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
อืมม.. ไล่โค้ดดูสักพักแล้วครับ ก็ไม่เห็นสิ่งผิดปกติอะไรใน php, ผมยังไม่ได้ดูในส่วนของ javascript
เอางี้ดีกว่า ลองใส่ echo หน้า $sql แบบนี้
echo $sql="insert into durable (Dur_id, Equnitkupun_id, Durtype_id, Attainment_id, Status_id, Provider_id, Dur_num, Dep_id, Dur_datewarity, Dur_dateincome, Dur_price, Dur_Brand, Dur_model, Dur_Fiscalyear, Dur_SerialNumber, Dur_name, pic) values ('$Dur_id', '$Equnitkupun_id', '$Durtype_id', '$Attainment_id', '$Status_id, '$Provider_id', '$Dur_num', '$Dep_id', '$Dur_datewarity', '$Dur_dateincome', '$Dur_price', '$Dur_Brand', '$Dur_model', '$Dur_Fiscalyear', '$Dur_SerialNumber', '$Dur_name', '$File_Images')";
จากนั้น submit form แล้วก็ลอง check $sql ที่มัน echo ออกมาดูว่าถูกต้องตามที่เราต้องการหรือเปล่า
Hope this help..
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2010-05-30 21:03:19 |
By :
pnbps |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ส่วนนี้เอาไว้ถูกที่ยังอะคับ เพราะเวลารันมันโดดไปที่ระบบผิดพลาดเลยครับ ช่วยอีกนิดนะครับ
if ($result) {
echo "<script>alert('ระบบบันทึกข้อมูล รหัส $_POST[Dur_id] เรียบร้อยแล้ว');window.location='form_durable.php?question_id=$question_id';</script>";
}
mysql_close();
}
else {
echo "<script>alert('ระบบผิดพลาด ไม่สามารถบันทึกข้อมูลนี้ได้ในขณะนี้');</script>";
}
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2010-05-31 11:12:01 |
By :
HaKonNan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 02
|