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 > ใส่ข้อมูลทาง checkbox และ text field พร้อมกัน แต่ข้อมูลในฐานข้อมูลไม่ตรงกับที่กรอกไว้ค่ะ



 

ใส่ข้อมูลทาง checkbox และ text field พร้อมกัน แต่ข้อมูลในฐานข้อมูลไม่ตรงกับที่กรอกไว้ค่ะ

 



Topic : 086765



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



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




หนูมีปัญหาเวลารับค่าจาก checkbox และ Text field พร้อมกันลงฐานข้อมูลค่ะ มันรับค่าตัวเลขไม่ถูกต้องหรือรับค่าไม่หมดค่ะ

- Checkbox ชื่อ income[]
- Text field ชื่อ price[]

อันนี้แบบฟอร์ม ใส่ข้อมูลครบทุกช่อง
cb1

ผลลัพธ์ในฐานข้อมูล
cb4


กรณีที่ 2
cb2

ผลลัพธ์
cb5


กรณีที่ 3
cb3

ผลลัพธ์
cb6


อันนี้เป็นโค๊ดสำหรับ Insert ข้อมูลเข้าไปนะคะ
Code (PHP)
<?
mysql_connect("localhost","root","root");
mysql_select_db("lph");

$date=date("j - F - Y");

for($i=0,$j=0 ;$i<count($_POST["income"]);$i++,$j++)
{
if($_POST["income"][$i] != "")
{
$strSQL = "INSERT INTO income (income_name , price , date) VALUES ( '".$_POST["income"][$i]."' , '".$_POST["price"][$j]."' ,'$date')";
mysql_query("set NAMES UTF8");
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");	
}
}

echo "<script>alert('Save complete');</script>";	

mysql_close();
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


อยากทราบว่าเป็นเพราะอะไรเหรอคะ? หนูไม่รู้ว่าโค๊ดผิดตรงไหน รบกวนขอคำแนะนำด้วยค่ะ



Tag : PHP, MySQL, HTML/CSS









ประวัติการแก้ไข
2012-11-15 11:36:00
2012-11-22 10:09:35
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-11-15 11:32:50 By : naomikijung View : 4415 Reply : 15
 

 

No. 1



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

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

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


ขอดู code form ด้วยได้ไหมครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-15 11:47:30 By : pokultra
 


 

No. 2

Guest


checkbox มันจะส่งค่าก็ต่อเมื่อทำการ เลือก ครับ ถึงแ่ม้จะตั้งชื่อเป็น array -> income[]

ส่วน

textbox มันจะส่งทั้งหมดที่มีครับ ถึงแ่ม้จะตั้งชื่อเป็น array ให้เหมือนกับ checkbox

อย่างในกรณีที่ 2

คุณเลือก checkbox คือ เงินเดือน กับ โบนัส

แต่ textbox มันไม่ได้ส่งค่าไปแค่ เงินเดือน โบนัส ครับ มันจะไปหมดเลยทั้ง เงินเดือน OT โบนัส


ค่า array มันจึงไม่ตรงกันครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-15 13:09:07 By : ไวยวิทย์
 

 

No. 3



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



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


ตอบความคิดเห็นที่ : 1 เขียนโดย : pokultra เมื่อวันที่ 2012-11-15 11:47:30
รายละเอียดของการตอบ ::
นี่ค่ะ

Code
<form id="form1" name="form1" method="post" action="test2.php">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="29" colspan="2"><strong>แก้ไขข้อมูล</strong></td>
</tr>
<tr>
<td height="30" colspan="2"><blockquote>
<p>รายรับ (เลือกได้มากกว่า 1 รายการ)</p>
</blockquote></td>
</tr>
<tr>
<td width="26%" height="32"><input name="income[]" type="checkbox" id="income[]" value="เงินเดือน" />
<label for="income[]">เงินเดือน </label>
<label for="price[]"></label></td>
<td width="74%"><input type="text" name="price[]" id="price[]" />
บาท</td>
</tr>
<tr>
<td height="30"><input name="income[]" type="checkbox" id="income[]" value="OT" />
<label for="income[]">OT</label></td>
<td><label for="price[]"></label>
<input type="text" name="price[]" id="price[]" />
บาท</td>
</tr>
<tr>
<td height="30"><input name="income[]" type="checkbox" id="income[]" value="โบนัส" />
โบนัส
<label for="income[]"> </label>
<label for="price[]"></label></td>
<td><input type="text" name="price[]" id="price[0]2" />
บาท</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="button" id="button" value="บันทึก" /></td>
</tr>
</table></form>


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-15 13:13:14 By : naomikijung
 


 

No. 4



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



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


ตอบความคิดเห็นที่ : 2 เขียนโดย : ไวยวิทย์ เมื่อวันที่ 2012-11-15 13:09:07
รายละเอียดของการตอบ ::
พอจะมีวิธีแก้ไข หรือ ตัวอย่างโค๊ดมั้ยคะ?

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-15 13:16:56 By : naomikijung
 


 

No. 5

Guest


แก้ไขก็เปลี่ยนชื่อ checkbox

จาก income[] เงินเดือน ก็เป็น salary , ot , bonus

ของ textbox

ก็เปลี่ยนเป็น salray_num, ot_num, bonus_num

เวลารับก็เปลี่ยนเป็น

$_POST['salary']

$_POST['salray_num']

แทนครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-15 13:30:42 By : ไวยวิทย์
 


 

No. 6



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

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

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


Quote:
ผลลัพธ์
INSERT INTO income (income_name , price , date) VALUES ( 'เงินเดือน' , '100' ,'17 - November - 2012')
INSERT INTO income (income_name , price , date) VALUES ( 'โบนัส' , '300' ,'17 - November - 2012')


Code (PHP)
 <form id="form1" name="form1" method="post" action="wage_saving.php">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="29" colspan="2"><strong>แก้ไขข้อมูล</strong></td>
</tr>
<tr>
<td height="30" colspan="2"><blockquote>
<p>รายรับ (เลือกได้มากกว่า 1 รายการ)</p>
</blockquote></td>
</tr>
<tr>
<td width="26%" height="32"><input name="income[salary]" type="checkbox" id="income[]" value="เงินเดือน" />
<label for="income[]">เงินเดือน </label>
<label for="price[]"></label></td>
<td width="74%"><input type="text" name="price[salary]" id="price[]" />
บาท</td>
</tr>
<tr>
<td height="30"><input name="income[OT]" type="checkbox" id="income[]" value="OT" />
<label for="income[]">OT</label></td>
<td><label for="price[]"></label>
<input type="text" name="price[OT]" id="price[]" />
บาท</td>
</tr>
<tr>
<td height="30"><input name="income[Bonus]" type="checkbox" id="income[]" value="โบนัส" />
โบนัส
<label for="income[]"> </label>
<label for="price[]"></label></td>
<td><input type="text" name="price[Bonus]" id="price[0]2" />
บาท</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="button" id="button" value="บันทึก" /></td>
</tr>
</table></form>


wage_saving.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
//print_r($_POST);
//mysql_query("set NAMES UTF8");
//mysql_connect("localhost","root","root");
//mysql_select_db("lph");

$date=date("j - F - Y");

foreach($_POST["income"] as $key => $value){
	$strSQL = "INSERT INTO income (income_name , price , date) VALUES ( '$value' , '{$_POST["price"]["$key"]}' ,'$date')";
	//$objQuery = mysql_query($strSQL) or die (mysql_error()."<br />\nError Query [".$strSQL."]");
	echo $strSQL."<br />";
}
echo "<script>alert('Save complete');</script>";

//mysql_close();
?>



ประวัติการแก้ไข
2012-11-17 16:52:12
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-17 16:51:24 By : sakuraei
 


 

No. 7



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



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


ตอบความคิดเห็นที่ : 5 เขียนโดย : ไวยวิทย์ เมื่อวันที่ 2012-11-15 13:30:42
รายละเอียดของการตอบ ::
ขอบคุณค่ะ แต่ว่าอยากได้เป็นแบบ array เผื่อว่ามีการเพิ่มข้อมูลอีกในอนาคตค่ะ



ตอบความคิดเห็นที่ : 6 เขียนโดย : sakuraei เมื่อวันที่ 2012-11-17 16:51:24
รายละเอียดของการตอบ ::
ขอบคุณค่ะ จะลองเอาไปดัดแปลงนะคะ ได้หรือไม่อย่างไรจะมาแจ้งให้ทราบค่ะ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-18 11:04:21 By : naomikijung
 


 

No. 8



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



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


ตอบความคิดเห็นที่ : 6 เขียนโดย : sakuraei เมื่อวันที่ 2012-11-17 16:51:24
รายละเอียดของการตอบ ::
ในฐานข้อมูล ฟิลด์ที่รับค่าจาก checkbox และ text field มันขึ้นคำว่า array ค่ะ



ประวัติการแก้ไข
2012-11-20 14:33:02
2012-11-20 14:33:19
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-20 14:24:43 By : naomikijung
 


 

No. 9



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

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

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


ไม่ค่อยเข้าใจ ลองจับภาพหน้าจอมาให้ดูหน่อยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-20 14:28:28 By : sakuraei
 


 

No. 10



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

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

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


เอาโค้ดมาลงให้ดูจะดีกว่าครับ เพราะโค้ดที่พี่ให้ไปมันใช้ได้แน่นอน
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-20 14:38:41 By : sakuraei
 


 

No. 11



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



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


ตอบความคิดเห็นที่ : 10 เขียนโดย : sakuraei เมื่อวันที่ 2012-11-20 14:38:41
รายละเอียดของการตอบ ::
รบกวนด้วยนะคะ

แบบฟอร์ม
Code (PHP)
<?
	session_start();
	if($_SESSION['username'] == "")
	{
		echo "<script>alert('Please login!');window.location='login.php';</script>";
		exit();
	}

	if($_SESSION['Status'] != "ADMIN")
	{
		echo "<script>alert('This page for Admin only!');window.location='login.php';</script>";
		exit();
	}	
	
	
	mysql_connect("localhost","root","root");
	mysql_select_db("lph");
	$strSQL = "SELECT * FROM admin WHERE username = '".$_SESSION['username']."' ";
	mysql_query("set NAMES UTF8");
	$objQuery = mysql_query($strSQL);
	$objResult = mysql_fetch_array($objQuery);
?>
<!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>

<script src="http://www.google.com/jsapi" type="text/javascript"></script>  
<script type="text/javascript">  
google.load("jquery", "1.3.2");  
</script>  
<script type="text/javascript">  
$(function(){  
	$("select#Datalist").change(function(){
		if($("select#Datalist option:selected").val()=="add"){
			$("select#Datalist").hide();
			$("input#addList").show();
			$("input#addButton").show();
		}
	});
	$("input#addButton").live("click",function(){
		var newOption="<option value=\""+$("input#addList").val()+"\" selected=\"selected\">"+$("input#addList").val()+"</option>";
		$("select#Datalist").show();
		$("select#Datalist option:last").after(newOption);
		$("input#addList").val("").hide();
		$("input#addButton").hide();
	});
});  
</script> 


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
	var i = 1; 
	$(function(){
		
		$('#btn-add').click(function(){
			
			if(i <= 5) {
				$('#group-textbox').append('<p><input type="text" name="income[]' + i + '" id="income' + i + '" /> </p>\n');
				i++;
			} else
				alert('เพิ่มได้สูงสุด 5 รายการเท่านั้น');
			
		});
		
		$('#btn-del').click(function(){
			var r = "input#income[]" + (i-1); // input#ตามด้วยชื่อ textbox
			if(i > 1) {
				 $(r).remove();
				 i--;
			} else 
				alert('ไม่มีรายการที่ต้องการลบ');
			
		});
	});
</script>

<!--ฟังก์ชันเพิ่ม textbox เงินหัก-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
	var j = 1; //กำหนดตัวแปรตามจำนวน textbox ที่ต้องให้แสดงเพิ่ม
	$(function(){	
		$('#btn-add2').click(function(){
			
			if(j <= 5) { 
				$('#group-textbox2').append('<p><input type="text" name="pay[]' + j + '" id="pay' + j + '" /> </p>\n');
				j++;
			} else
				alert('เพิ่มได้สูงสุด 5 รายการเท่านั้น');
			
		});
		
		$('#btn-del2').click(function(){
			var r = "input#pay[]" + (j-1); // input#ตามด้วยชื่อ textbox
			if(j > 1) {
				 $(r).remove();
				 j--;
			} else 
				alert('ไม่มีรายการที่ต้องการลบ');
			
		});
	});
</script>

<style type="text/css">
body,td,th {
	font-family: "MS Sans Serif", "Angsana New", "Cordia New";
	font-size: 16px;
	color: #000;
}
body {
	background-image: url();
}
</style>
</head>

<body>
<?php include("config.inc.php"); 

$sql = "select * from $tbemployee where idcard=$idcard;";
mysql_query("set NAMES UTF8");
$result = mysql_query($sql);
$arr = mysql_fetch_array($result); //คำสั่งเรียกดูข้อมูลแบบ array

?>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top" bgcolor="#666666"><br><table width="990" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td bgcolor="#666666"><table width="990" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td background="image/bg1_1_1.png"><table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td align="center"></td>
      </tr>
      </table>
          <table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td colspan="3"><img src="image/h1_edit.png" width="900" height="30" /></td>
              </tr>
            <tr>
              <td width="30" background="image/h3.jpg">&nbsp;</td>
              <td valign="top" bgcolor="#FFFFFF"><form id="form1" name="form1" method="post" action="edit_money3.php">
              <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="29" colspan="2"><strong>เพิ่มข้อมูลทางการเงิน</strong></td>
  </tr>
  <tr>
  <td height="30"><label for="idcard">
    <blockquote>
      <p>เลขบัตรประจำตัวประชาชน</p>
    </blockquote>
  </label>
</td>
  <td height="30">
        <input name="idcard" type="text" id="idcard" value="<?=$arr["idcard"];?>" size="50" readonly="readonly" /></td>
  </tr>
  <tr>
    <td height="30"><label for="name">
      <blockquote>
        <p>ชื่อ - นามสกุล</p>
      </blockquote>
    </label>

</td>
    <td height="30">          <input name="name" type="text" id="name" value="<?=$arr["name"];?>" size="50" readonly="readonly" />
</td>
  </tr>
  <tr>
    <td height="30"><label for="office">
      <blockquote>
        <p>หน่วยงาน</p>
      </blockquote>
    </label>

</td>
    <td height="30">          <input name="office" type="text" id="office" value="<?=$arr["office"];?>" size="50" readonly="readonly" />
</td>
  </tr>
  <tr>
        <td height="30" colspan="2"><blockquote>
      <label for="years">ปี : </label>
      <select name="years" id="years">
        <option selected="selected">-เลือก-</option>
        <option value="2556">2556</option>
        <option value="2555">2555</option>
      </select>
      <label for="month"> เดือน : </label>
      <select name="month" id="month">
        <option selected="selected">-เลือก-</option>
        <option value="มกราคม">มกราคม</option>
        <option value="กุมภาพันธ์">กุมภาพันธ์</option>
        <option value="มีนาคม">มีนาคม</option>
        <option value="เมษายน">เมษายน</option>
        <option value="พฤษภาคม">พฤษภาคม</option>
        <option value="มิถุนายน">มิถุนายน</option>
        <option value="กรกฎาคม">กรกฎาคม</option>
        <option value="สิงหาคม">สิงหาคม</option>
        <option value="กันยายน">กันยายน</option>
        <option value="ตุลาคม">ตุลาคม</option>
        <option value="พฤศจิกายน">พฤศจิกายน</option>
        <option value="ธันวาคม">ธันวาคม</option>
      </select>
    </blockquote></td>

  </tr>
  <tr>
    <td height="30" colspan="2">1. <strong>รายการรับ</strong> (เลือกได้มากกว่า 1 รายการ)</td>
  </tr>
  <tr>
    <td width="34%" height="32"><input name="income[salary]" type="checkbox" id="income[salary]" value="เงินเดือน" />
      <label for="income[salary]">เงินเดือน </label>
      <label for="price[gov2]"></label></td>
    <td width="66%"><input type="text" name="price[salary]" id="price[salary]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[salary2]" type="checkbox" id="income[salary2]" value="ตกเบิกเงินเดือน" />
      <label for="income[salary]">ตกเบิกเงินเดือน</label></td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[salary2]" id="price[salary2]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[emolu]" type="checkbox" id="income[emolu]" value="เงินประจำตำแหน่ง" />
      เงินประจำตำแหน่ง 
        <label for="income[salary]"> </label>
        <label for="price[gov2]"></label></td>
    <td><input type="text" name="price[emolu]" id="price[emolu]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[emolu2]" type="checkbox" id="income[emolu2]" value="ตกเบิกเงินประจำตำแหน่ง" />
      <label for="income[salary]">ตกเบิกเงินประจำตำแหน่ง</label></td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[emolu2]" id="price[emolu2]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[monthly]" type="checkbox" id="income[monthly]" value="ค่าตอบแทนรายเดือน" />
      <label for="income[salary]"></label>
      ค่าตอบแทนรายเดือน 
      <label for="income[salary]"> </label>
      <label for="price[gov2]"></label></td>
    <td><input type="text" name="price[monthly]" id="price[monthly]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="32"><input name="income[temp]" type="checkbox" id="income[temp]" value="เงินเพิ่มค่าครองชีพชั่วคราว" />
      <label for="income[salary]">เงินเพิ่มค่าครองชีพชั่วคราว</label></td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[temp]" id="price[temp]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="32"><input name="income[full]" type="checkbox" id="income[full]" value="ค่าตอบแทนพิเศษเงินเดือนเต็มขั้น" />
      <label for="income[salary]"></label>
      ค่าตอบแทนพิเศษเงินเดือนเต็มขั้น 
      <label for="income[salary]"> </label>
      <label for="price[gov2]"></label></td>
    <td><input type="text" name="price[full]" id="price[full]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="32"><input name="income[ph]" type="checkbox" id="income[ph]" value="เงินค่าตอบแทนบุคลากรสาธารณสุข" />
      <label for="income[salary]"></label>
      เงินค่าตอบแทนบุคลากรสาธารณสุข 
      <label for="income[salary]"> </label>
      <label for="price[gov2]"></label></td>
    <td><input type="text" name="price[ph]" id="price[ph]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[pts]" type="checkbox" id="income[pts]" value="พตส." />
      <label for="income[salary]"></label>
      เงิน พตส. 
      <label for="income[salary]"> </label>
      <label for="price[gov2]"></label></td>
    <td><input type="text" name="price[pts]" id="price[pts]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[pts2]" type="checkbox" id="income[pts2]" value="พตส. ชั่วคราว" />
      <label for="income[salary]">เงิน พตส. ชั่วคราว</label></td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[pts2]" id="price[pts2]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[pts3]" type="checkbox" id="income[pts3]" value="พตส. ไม่คำนวณภาษี" />
      <label for="income[salary]">เงิน พตส. (ไม่คำนวณภาษี)</label></td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[pts3]" id="price[pts3]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[ot]" type="checkbox" id="income[ot]" value="OT" />
      <label for="income[salary]"></label>
      ค่าตอบแทนปฏิบัติงานนอกเวลา (OT) 
      <label for="income[salary]"> </label>
      <label for="price[gov2]"></label></td>
    <td><input type="text" name="price[ot]" id="price[ot]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="33"><input name="income[turn]" type="checkbox" id="income[turn]" value="ค่าเวร" />
      <label for="income[salary]">ค่าเวร</label></td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[turn]" id="price[turn]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="33"><input name="income[overt]" type="checkbox" id="income[overt]" value="ค่าล่วงเวลาคลินิกพิเศษ" />
      <label for="income[salary]"></label>
      ค่าล่วงเวลาคลินิกพิเศษ 
      <label for="income[salary]"> </label>
      <label for="price[gov2]"></label></td>
    <td><input type="text" name="price[overt]" id="price[overt]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="33"><input name="income[inves]" type="checkbox" id="income[inves]" value="ค่าตอบแทนชันสูตรพลิกศพ" />
      <label for="income[salary]"></label>
      ค่าตอบแทนชันสูตรพลิกศพ 
      <label for="income[salary]"> </label>
      <label for="price[gov2]"></label></td>
    <td><input type="text" name="price[inves]" id="price[inves]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[ems]" type="checkbox" id="income[ems]" value="EMS" />
      <label for="income[salary]"></label>
      ค่าตอบแทนนอกเวลา (EMS) 
      <label for="income[salary]"> </label>
      <label for="price[gov2]"></label></td>
    <td><input type="text" name="price[ems]" id="price[ems]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[doc]" type="checkbox" id="income[doc]" value="เงินเพิ่มพิเศษแพทย์ (ไม่ทำเวชปฎิบัติส่วนตัว)" />
      <label for="income[salary]">เงินเพิ่มพิเศษแพทย์ (ไม่ทำเวชปฎิบัติส่วนตัว)</label></td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[doc]" id="price[doc]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[doc2]" type="checkbox" id="income[doc2]" value="เงินเพิ่มพิเศษแพทย์ (สาขาส่งเสริมพิเศษ)" />
      <label for="income[salary]">เงินเพิ่มพิเศษแพทย์ (สาขาส่งเสริมพิเศษ)</label></td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[doc2]" id="price[doc2]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[teach]" type="checkbox" id="income[teach]" value="ค่าสอนนักศึกษาแพทย์" />
      <label for="income[salary]">ค่าสอนนักศึกษาแพทย์</label></td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[teach]" id="price[teach]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="30"><input name="income[refree]" type="checkbox" id="income[refree]" value="ค่าตอบแทนกรรมการตรวจการจ้าง" />
      <label for="income[salary]"></label>
      ค่าตอบแทนกรรมการตรวจการจ้าง 
      <label for="income[salary]"> </label>
      <label for="price[gov2]"></label></td>
    <td><input type="text" name="price[refree]" id="price[refree]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="31"><input name="income[pro]" type="checkbox" id="income[pro]" value="เงินพิเศษโครงการปฐมภูมิ (รพ.แออัด)" />
      <label for="income[salary]">เงินพิเศษโครงการปฐมภูมิ (รพ.แออัด)</label></td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[pro]" id="price[pro]" />
      บาท</td>
  </tr>
  <tr>
    <td height="31"><input name="income[gov]" type="checkbox" id="income[gov]" value="ค่าเช่าบ้านข้าราชการ" />
      <label for="income[salary]">ค่าเช่าบ้านข้าราชการ</label></td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[gov]" id="price[gov]" />
      บาท</td>
  </tr>
  <tr>
    <td height="31"><input name="income[cure]" type="checkbox" id="income[cure]" value="ค่ารักษาพยาบาล" />
      <label for="income[salary]">ค่ารักษาพยาบาล</label></td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[cure]" id="price[cure]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="31"><input name="income[child]" type="checkbox" id="income[child]" value="ค่าเล่าเรียนบุตร" />
      <label for="income[salary]"></label>
      ค่าเล่าเรียนบุตร</td>
    <td><label for="price[gov2]"></label>
      <input type="text" name="price[child]" id="price[child]" />
      บาท</td>
  </tr>
  <tr>
    <td height="31"><input name="income[bonus]" type="checkbox" id="income[bonus]" value="โบนัส" />
      <label for="income[salary]"></label>
      โบนัส 
      <label for="income[salary]"> </label>
      <label for="price[gov2]"></label></td>
    <td><input type="text" name="price[bonus]" id="price[bonus]" /> 
      บาท</td>
  </tr>
  <tr>
    <td height="31"><input name="income[gov2]" type="checkbox" id="income[gov2]" value="ค่าเดินทางไปราชการ" />
      <label for="income[salary]"></label>
      ค่าเดินทางไปราชการ 
      <label for="income[salary]"> </label>
      <label for="price[gov2]"></label></td>
    <td><input type="text" name="price[gov2]" id="price[0]" /> 
      บาท</td>
  </tr>
  <tr>
    <td colspan="2"><div id="group-textbox">อื่นๆ โปรดระบุ</div>
      <input type="button" id="btn-add" value="เพิ่มรายการ" />
      <input type="button" id="btn-del" value="ลบรายการ" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input type="submit" name="button" id="button" value="OK" /></td>
  </tr>
</table></form></td>
              <td width="30" background="image/h4.jpg">&nbsp;</td>
            </tr>
            <tr>
              <td colspan="3"><img src="image/h2_edit.png" width="900" height="30" /></td>
              </tr>
          </table>
          <br>
          <p>&nbsp;</p></td>
      </tr>
      <tr>
        <td height="60" valign="top" background="image/bg2.png"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td align="center"></td>
          </tr>
        </table></td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>




หน้าบันทึกข้อมูล
Code (PHP)
<?
	session_start();
	
	mysql_connect("localhost","root","root");
	mysql_select_db("lph");
	
	$date=date("j - F - Y");
	
	foreach($_POST["income"] as $key => $value){
	$strSQL = "INSERT INTO income (name , years , month, office , income_name , price , date) VALUES ( '$name' , '$years' , '$month' , '$office', '$value' , '{$_POST["price"]["$key"]}' ,'$date')";
	//$objQuery = mysql_query($strSQL) or die (mysql_error()."<br />\nError Query [".$strSQL."]");
	echo $strSQL."<br />";
}
echo "<script>alert('Save complete');</script>";

		?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />




ตอนนี้ถ้าแบบนี้มันปกตินะคะ แต่พอไปดูที่ฐานข้อมูลพบว่าข้อมูลไม่เข้าค่ะ (ตอนแรกขึ้นแค่ array)
Code
INSERT INTO income (name , years , month, office , income_name , price , date) VALUES ( 'สมบัติ ผู้ดี' , '2555' , 'พฤศจิกายน' , 'งานบริการรักษาความปลอดภัย', 'เงินเดือน' , '5000' ,'21 - November - 2012')
INSERT INTO income (name , years , month, office , income_name , price , date) VALUES ( 'สมบัติ ผู้ดี' , '2555' , 'พฤศจิกายน' , 'งานบริการรักษาความปลอดภัย', 'ค่าเวร' , '1500' ,'21 - November - 2012')




ประวัติการแก้ไข
2012-11-21 10:17:25
2012-11-21 10:19:53
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-21 10:13:41 By : naomikijung
 


 

No. 12



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

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

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


เอาโครงสร้างตารางและข้อมูลในตารางมาให้ดูด้วยครับ
จับภาพหน้าจอมาเลยครับ

ผมสงสัยว่าชนิดข้อมูลของฟิวด์แต่ละฟิวด์ มันไม่ตรงกับข้อมูลที่ป้อนเข้าไปหรือเปล่า

ลองลบข้อมูลออกทั้งหมดดูน่ะครับ แล้วค่อยบันทึกข้อมูลใหม่


ประวัติการแก้ไข
2012-11-21 13:28:37
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-21 12:54:24 By : sakuraei
 


 

No. 13



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



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


ตอบความคิดเห็นที่ : 12 เขียนโดย : sakuraei เมื่อวันที่ 2012-11-21 12:54:24
รายละเอียดของการตอบ ::
ต้องขออภัยด้วยค่ะ พอดีเผลอลบข้อมูลในตารางก่อนหน้าไปแล้ว เลยได้แค่โครงสร้างตารางค่ะ
TB

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-22 08:53:54 By : naomikijung
 


 

No. 14



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

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

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


หน้าบันทึกข้อมูล(แก้ไข) ลองดูอีกทีน่ะครับ และช่วยจับภาพหน้าข้อมูลหลังการบันทึกด้วยครับ
<?php
	session_start();
	
	mysql_connect("localhost","root","root");
	mysql_select_db("lph");
	
	$date=date("j - F - Y");
	
	foreach($_POST["income"] as $key => $value){
		$strSQL = "INSERT INTO income (name , years , month, office , income_name , price , date) VALUES ( '$name' , '$years' , '$month' , '$office', '$value' , '{$_POST["price"][$key]}' ,'$date')";
		$objQuery = mysql_query($strSQL) or die (mysql_error()."<br />\nError Query [".$strSQL."]");
		echo $strSQL."<br />";
	}
	echo "<script>alert('Save complete');</script>";
?>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />



แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-22 11:15:33 By : sakuraei
 


 

No. 15



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



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


ตอบความคิดเห็นที่ : 14 เขียนโดย : sakuraei เมื่อวันที่ 2012-11-22 11:15:33
รายละเอียดของการตอบ ::
ขอบคุณค่ะ!! ผลลัพธ์ออกมาถูกต้องแล้วค่ะ
checkbox2

Code
INSERT INTO income (idcard, name , years , month, office , income_name , price , date) VALUES ( '1520099345677', 'สมบัติ ผู้ดี' , '2555' , 'พฤศจิกายน' , 'งานบริการรักษาความปลอดภัย', 'ค่าตอบแทนรายเดือน' , '3000' ,'22 - November - 2012')
INSERT INTO income (idcard, name , years , month, office , income_name , price , date) VALUES ( '1520099345677', 'สมบัติ ผู้ดี' , '2555' , 'พฤศจิกายน' , 'งานบริการรักษาความปลอดภัย', 'OT' , '1500' ,'22 - November - 2012')


ผลลัพธ์
checkbox1

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-22 16:25:13 By : naomikijung
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ใส่ข้อมูลทาง checkbox และ text field พร้อมกัน แต่ข้อมูลในฐานข้อมูลไม่ตรงกับที่กรอกไว้ค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 อัตราราคา คลิกที่นี่