Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > เลือกข้อมูลใน list แล้วต้องการบันทึกในฐานข้อมูลต้องทำยังไงครับ



 

เลือกข้อมูลใน list แล้วต้องการบันทึกในฐานข้อมูลต้องทำยังไงครับ

 



Topic : 072475



โพสกระทู้ ( 22 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook



ต้องการจัดเก็บใน
Code
CREATE TABLE `tb_serial` (
`serial_id` int(5) NOT NULL auto_increment,
`serial_name` varchar(70) NOT NULL,
`type_id` int(4) NOT NULL,
`model_id` int(4) NOT NULL,
`username` varchar(50) NOT NULL,
PRIMARY KEY (`serial_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=16 ;



จะเก็บ type_id ซึ่งเลือกมาจาก ตาราง tb_typeและ medel_id มาจากตาราง tb_model
จะต้องแก้ไขส่วนไหนบ้างครับ



Code (PHP)
<?php ob_start(); ?>
<?php require_once('../Connections/connection.php'); ?>
<?
	//mysql_connect("localhost","root","root") or die(mysql_error());
	//mysql_select_db("tot_wherehouse");
	
?>

<script type="text/javascript">
var select1 = new Array();
var select2 = new Array();
</script>

<?php if (isset($_POST['btnInsert'])) { // กรณีที่คลิกปุ่ม "เพิ่มข้อมูล"
	// ตรวจสอบหมายเลขห้องพักซ้ำหรือไม่
	mysql_select_db($database_connection, $connection);
	$query_rcsR = "SELECT * FROM tb_serial WHERE type_id = '".$_POST['name2']."' AND serial_name = '".$_POST['txtserial']."'";
	$rcsR = mysql_query($query_rcsR, $connection) or die(mysql_error());
	$totalRows_rcsR = mysql_num_rows($rcsR);
 	if($totalRows_rcsR == 0){ // ถ้าหมายเลขห้องพักไม่ซ้ำ จะ Insert ได้
	 	$insertSQL = "INSERT INTO tb_serial (type_id, model_id, serial_name) VALUES ('".$_POST['name1']."', '".$_POST['name2']."', '".$_POST['txtserial']."')";
  		mysql_select_db($database_connection, $connection);
  		$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
		if(empty($Result1)){ // แจ้งผลการ Insert ข้อมูล
			//$alert_msg = "ไม่สามารถเพิ่มข้อมูลห้องพักนี้ได้";
			echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
  			echo "<script language='javascript'>alert('ไม่สามารถเพิ่มข้อมูลได้')</script>";
  			echo "<meta http-equiv='refresh' content='0;URL=/TOT_WhereHouse/receive_equipment/manage_equipment.php'>";
		}else{
			//$alert_msg = "เพิ่มข้อมูลเรียบร้อยแล้ว";
			echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
  			echo "<script language='javascript'>alert('เพิ่มข้อมูลเรียบร้อยแล้ว')</script>";
  			echo "<meta http-equiv='refresh' content='0;URL=/TOT_WhereHouse/receive_equipment/manage_equipment.php?pane2'>";
		}
	}else{ // ถ้าหมายเลขห้องพักซ้ำ จะแจ้งแก่ผู้ใช้
			//$alert_msg = "หมายเลขห้องนี้มีอยู่แล้ว ไม่สามารถเพิ่มซ้ำได้";
			echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
  			echo "<script language='javascript'>alert('ไม่สามารถเพิ่มข้อมูลได้')</script>";
  			echo "<meta http-equiv='refresh' content='0;URL=/TOT_WhereHouse/receive_equipment/manage_equipment.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>

<script src="../SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="406"><form action="manage_equipment.php" method="post" >
	<tr class="Content AlertMsg">
		<td colspan="2" align="center">&nbsp;dasdfasd</td>
	</tr>
	<tr class="Content">
		<td width="22%" align="right"><font class="AlertMsg">*</font> Serial Number: </td>
		<td width="78%"><input type="text" name="txtserial" id="txtserial"/></td>
	</tr>
	<tr class="Content">
  		<td align="right"><font class="AlertMsg">*</font> ประเภทอุปกรณ์ : </td>
  		<td>
        <select id="id_select[1]" name="name1" onChange="return show_select_next(1,2,select2)" ><option value="select1">--- Please Select Type ---</option>
        
        
        
        
        </select>
        </td>
	</tr>
    <tr class="Content">
  		<td align="right"><font class="AlertMsg">*</font> รุ่น : </td>
  		<td><select id="id_select[2]" name="name2"><option value="select2">--- Please Select Model ---</option></select>
          </td>
	</tr>
	<tr class="Content"><td colspan="2" align="center">
    	<input type="submit" name="btnInsert" value="เพิ่มข้อมูล" />
    	<input type="reset" name="btnReset" value="ล้างข้อมูล" />
	</td></tr>
	</form></table>
</body>
</html>

<?

$select1 = mysql_query("SELECT * FROM tb_type");
for($s1=0;$s1<mysql_num_rows($select1);$s1++)
{
$arr_s1=mysql_fetch_array($select1);
// echo $arr_s1['name_s1'];
?>
<script language="javascript">
select1[<?=$s1?>] = '<?=$arr_s1['equType_name']?>';
select2['<?=$arr_s1['equType_name']?>'] = new Array();
</script>
<?
// echo "<br>";
$select2 = mysql_query("SELECT * FROM tb_model where type_id = '".$arr_s1['type_id']."'");
for($s2=0;$s2<mysql_num_rows($select2);$s2++)
{

$arr_s2=mysql_fetch_array($select2);
// echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'-- ".$arr_s2['name_s2'];

?>
<script language="javascript">
select2['<?=$arr_s1['equType_name']?>'][<?=$s2?>] = '<?=$arr_s2['model_name']?>';

</script>

<?
// echo "<br>";

}
// echo "<br>";
}

?>

<script type="text/javascript">
var options1 = (parseFloat(select1.length)+1);
document.getElementById('id_select[1]').length = options1;
for(var ss1 = 1; ss1 < options1; ss1++)
{
document.getElementById('id_select[1]').options[ss1].text = select1[ss1-1];
document.getElementById('id_select[1]').options[ss1].value = select1[ss1-1];
}
function show_select_next(change_select,select_next,array_next)
{
var id_next = select_next ;
while(document.getElementById('id_select['+id_next+']'))
{
document.getElementById('id_select['+id_next+']').length=1;
document.getElementById('id_select['+id_next+']').options[0].selected =true
id_next++;
}
var name_text ;
var num_options = (parseFloat(array_next[document.getElementById('id_select['+change_select+']').value].length)+1);
document.getElementById('id_select['+select_next+']').length = num_options;

for(var nn = 1; nn < num_options; nn++)
{
name_text = array_next[document.getElementById('id_select['+change_select+']').value][nn-1];
document.getElementById('id_select['+select_next+']').options[nn].text = name_text;
document.getElementById('id_select['+select_next+']').options[nn].value = name_text;
}
}
</script>




Tag : PHP, MySQL, CakePHP









ประวัติการแก้ไข
2012-01-23 16:43:47
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-01-23 16:36:32 By : dragon_ball_king View : 898 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ใช้การอ่านแบบ $_POST ปกติครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-24 09:26:56 By : webmaster
 


 

No. 2



โพสกระทู้ ( 22 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

Code (PHP)
$insertSQL = "INSERT INTO tb_serial (type_id, model_id, serial_name) VALUES ('".$_POST['name1']."', '".$_POST['name2']."', '".$_POST['txtserial']."')";


Code (PHP)
<select id="id_select[1]" name="name1" onChange="return show_select_next(1,2,select2)" ><option value="select1">--- Please Select Type ---</option></select>

<select id="id_select[2]" name="name2"><option value="select2">--- Please Select Model ---</option></select>


ครับ กดตกลงแล้วค่าที่ได้จาก name1 และ name 2 มันมีค่า=0 ครับ มันไม่เก็บ type_id และ model_id ที่เราได้เลือกจาก listbox อะครับ
ช่วยแก้ให้หน่อยครับ


ประวัติการแก้ไข
2012-01-24 10:14:34
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-24 10:12:33 By : dragon_ball_king
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : เลือกข้อมูลใน list แล้วต้องการบันทึกในฐานข้อมูลต้องทำยังไงครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่