|
 |
|
มีปัญหาเรื่องโค้ด php ไม่สามารถบันทึกข้อมูลลง DB ได้คะ |
|
 |
|
|
 |
 |
|
ภาพจากตาราง insert

ภาพจากตาราง status

ปัญหาคือไม่สามารถบันทึกข้อมูลลง DB ได้คะ
exxxxxx.php
Code (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=utf-8" />
<title>Untitled Document</title>
<link href="flick/jquery-ui-1.8.22.custom.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function AddOk(pathfile)
{
document.getElementById('showdetail').innerHTML = 'เพิ่มข้อมูลเสร็จเรียบร้อยแล้ว';
document.getElementById('submit').disabled = false;
document.getElementById('AddPForm').reset() ;
return true ;
}
</script>
<script src="SpryAssets/SpryValidationRadio.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
</head>
<body>
<form id="AddPForm" method="post" enctype="multipart/form-data" action="Add_data.php" onsubmit="return senddata();">
<table width="950" border="0" align="center">
<tr><td colspan="3"><h2>บันทึกข้อมูล</h2></td><td> </td></tr>
<tr><td><p>วัน/เดือน/ปี(ที่รับเอกสาร)</p></td>
<td><input type="text" name="date_recevied" id="date_recevied" />
<div id="Calendar">
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.22.custom.js"></script>
<script> $(function(){
$("#date_recevied").datepicker();});
</script></div></td>
<td width="50" height="27"> </td>
<td width="318"> </td></tr>
<tr><td><p>วัน/เดือน/ปี(ที่ส่งเอกสาร)</p></td>
<td><input type="text" name="date_export" id="date_export" />
<div id="Calendar">
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.22.custom.js"></script>
<script> $(function(){
$("#date_export").datepicker();});
</script></div></td><td> </td><td> </td></tr>
<tr>
<td><p>เลขที่หนังสือ</p></td>
<td><input type="text" name="book_no" id="book_no"/></td><td> </td><td> </td></tr>
<tr><td><p>เลขที่หนังสือรับ</p></td><td>
<input type="text" name= "book_no_recevied" id="book_no_recevied" /></td>
<td> </td><td> </td></tr>
<tr><td><p>สถานะ</p></td>
<td><label><input type="radio" name="status_id" value="radio" id="1">ได้รับแล้ว</label>
<label><input type="radio" name="status_id" value="radio" id="2">รออนุมัติ</label>
<label><input type="radio" name="status_id" value="radio" id="3">ส่งออกแล้ว</label>
<br></td><td> </td><td> </td></tr>
<tr><td> </td>
<td><input type="submit" name="submit" id="submit" value="บันทึกข้อมูล" />
<input type="reset" name="reset" id="reset" value="ล้างข้อมูล" /></td>
<td> </td><td> </td></tr>
</table>
<span id="showdetail"></span>
</form>
</body>
</html>
add_data.php
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=tis620">
<?php
require_once ('Connections/DbConnect.php');
$sql=" INSERT INTO insert
(insert_id,book_no,book_no_recevied,date_recevied,date_export) values('$insert_id','$book_no','$book_no_recevied','$date_recevied','$date_export')";
mysql_db_query($DBName,"SET NAMES tis620");
$sqlquery=mysql_db_query($DBName,$sql) or die("ไม่สามารถเพิ่มข้อมูลได้ กรุณาตรวจสอบข้อมูลอีกครั้ง");
mysql_close();
print"เพิ่มข้อมูลเรียบร้อย";
?>
รบกวน(อีกแล้ว)พี่ๆด้วยนะคะ
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, jQuery

|
ประวัติการแก้ไข 2012-08-13 15:58:11 2012-08-13 15:58:45
|
 |
 |
 |
 |
Date :
2012-08-13 15:57:06 |
By :
custer |
View :
1425 |
Reply :
9 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมคิดว่าน่าจะมีปัญหาตรง add ข้อมูลลงฐานข้อมูลแหละครับ
จาก
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=tis620">
<?php
require_once ('Connections/DbConnect.php');
$sql=" INSERT INTO insert
(insert_id,book_no,book_no_recevied,date_recevied,date_export) values('$insert_id','$book_no','$book_no_recevied','$date_recevied','$date_export')";
mysql_db_query($DBName,"SET NAMES tis620");
$sqlquery=mysql_db_query($DBName,$sql) or die("ไม่สามารถเพิ่มข้อมูลได้ กรุณาตรวจสอบข้อมูลอีกครั้ง");
mysql_close();
print"เพิ่มข้อมูลเรียบร้อย";
น่าจะมีปัญหาตรงข้อมูลที่เพิ่มลงฐานข้อมูลในฟิลด์ชื่อ insert_id อ่ะครับ คุณกำหนดไว้ให้ระบบมันรันอัตโนมัติ น่าจะเขียนแบบนี้
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=tis620">
<?php
require_once ('Connections/DbConnect.php');
$sql=" INSERT INTO insert
(insert_id,book_no,book_no_recevied,date_recevied,date_export) values('','$book_no','$book_no_recevied','$date_recevied','$date_export')";
mysql_db_query($DBName,"SET NAMES tis620");
$sqlquery=mysql_db_query($DBName,$sql) or die("ไม่สามารถเพิ่มข้อมูลได้ กรุณาตรวจสอบข้อมูลอีกครั้ง");
mysql_close();
print"เพิ่มข้อมูลเรียบร้อย";
|
 |
 |
 |
 |
Date :
2012-08-13 16:03:19 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง Echo "$sql" ออกมาดูครับ
แล้วเอาไปรันใน mysql ดู
|
 |
 |
 |
 |
Date :
2012-08-13 16:25:12 |
By :
Krungsri |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็อาจจะเป็นไปได้ครับ ลองเอาโค๊ดเชื่อมต่อกับฐานข้อมูลมาดูครับ
|
 |
 |
 |
 |
Date :
2012-08-13 16:53:46 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 5 เขียนโดย : arm8957 เมื่อวันที่ 2012-08-13 16:53:46
รายละเอียดของการตอบ ::
DbConnect.php
Code (PHP)
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_DbConnect = "localhost";
$database_DbConnect = "user_login";
$username_DbConnect = "root";
$password_DbConnect = "1234";
$DbConnect = mysql_pconnect($hostname_DbConnect, $username_DbConnect, $password_DbConnect) or trigger_error(mysql_error(),E_USER_ERROR);
?>
Add_data.php
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=tis620">
<?php
require_once ('Connections/DbConnect.php');
$sql=" INSERT INTO insert
(insert_id,book_no,book_no_recevied,date_recevied,date_export) values('','$book_no','$book_no_recevied','$date_recevied','$date_export')";
mysql_db_query($dbname,"SET NAMES tis620");
$sqlquery=mysql_db_query($dbname,$sql) or die("ไม่สามารถเพิ่มข้อมูลได้ กรุณาตรวจสอบข้อมูลอีกครั้ง");
mysql_close();
print"เพิ่มข้อมูลเรียบร้อย";
?>
|
 |
 |
 |
 |
Date :
2012-08-13 16:59:24 |
By :
custer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองบัคโปรแกรมดูครับในหน้า add_data.php
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=tis620">
<?php
require_once ('Connections/DbConnect.php');
$sql=" INSERT INTO insert
(insert_id,book_no,book_no_recevied,date_recevied,date_export) values('','$book_no','$book_no_recevied','$date_recevied','$date_export')";
mysql_db_query($dbname,"SET NAMES tis620");
$sqlquery=mysql_db_query($dbname,$sql) or die("ไม่สามารถเพิ่มข้อมูลได้ กรุณาตรวจสอบข้อมูลอีกครั้ง<br /> Mysql report : ".mysql_error());
mysql_close();
print"เพิ่มข้อมูลเรียบร้อย";
?>
|
 |
 |
 |
 |
Date :
2012-08-13 17:15:57 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก DbConnect.php
$database_DbConnect = "user_login"; โค้ด Connect ใช้ database_DbConnect
แต่จาก Add_data.php
mysql_db_query($dbname,"SET NAMES tis620");
ดาต้าเบสใช้ $dbname
เกี่ยวหรือเปล่าไม่แน่ใจ แต่ผมว่ามันคนละค่ากัน
|
 |
 |
 |
 |
Date :
2012-08-13 20:56:31 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อาจเป็นเพราะยังไม่ได้เลือก Database
|
 |
 |
 |
 |
Date :
2012-08-13 21:24:18 |
By :
Krungsri |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|