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,028

HOME > PHP > PHP Forum > ส่งข้อมูลรายการซ่อมไปแบบ minit checkbox ถ้าติกถูก เข้าได้ ถ้าไม่ติก จะเข้าไม่ได้ ฟ้อง error ว่า คุณไม่ได้ใส่หรือติกถูก



 

ส่งข้อมูลรายการซ่อมไปแบบ minit checkbox ถ้าติกถูก เข้าได้ ถ้าไม่ติก จะเข้าไม่ได้ ฟ้อง error ว่า คุณไม่ได้ใส่หรือติกถูก

 



Topic : 083350



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



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



สวัสดีครับ ผมมีปัญหาเกี่ยวกับ check box แบบ มัลติ ครับ ปัญหาคือ เมื่อผมติกถูกระบบจะเซฟเข้าระบบ

ภาพแรก ฐานข้อมูล
db

ภาพสอง ฟอร์มการส่งซ่อม ติกบางตัว ไม่ติกบางตัว
หน้าจอ

หลังการส่งค่าเข้าระบบแล้ว ระบบจะทำการบันทึก แต่ค่าที่เราติกถูกภาพสองนั้นจะไม่ฟ้อง error แต่ค่าที่ไม่ติก จะฟ้อง error เหมือนว่าผมไม่ได้ติก อย่างภาพที่ 3
error

สรุปปัญหา : ถ้าติกไม่ error แต่ไม่ติก error ตามภาพ ขอบคุณล้วงหน้าครับผม



Tag : PHP, MySQL, JavaScript, Windows









ประวัติการแก้ไข
2012-09-03 02:18:41
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-09-03 02:18:02 By : veeitdata5 View : 1062 Reply : 5
 

 

No. 1



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

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

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

Code (form.php)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<script language="JavaScript">
	function onSave()
	{
		if(confirm('Do you want to save ?')==true)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
</script>
<form name="frmMain" action="save.php" method="post" OnSubmit="return onSave();">
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
  <tr>
    <th width="91"> <div align="center">CustomerID </div></th>
    <th width="98"> <div align="center">Name </div></th>
    <th width="198"> <div align="center">Email </div></th>
    <th width="97"> <div align="center">CountryCode </div></th>
    <th width="59"> <div align="center">Budget </div></th>
    <th width="71"> <div align="center">Used </div></th>
    <th width="30"> <div align="center">Select </div></th>
  </tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
  <tr>
    <td><div align="center"><?=$objResult["CustomerID"];?></div></td>
    <td><?=$objResult["Name"];?></td>
    <td><?=$objResult["Email"];?></td>
    <td><div align="center"><?=$objResult["CountryCode"];?></div></td>
    <td align="right"><?=$objResult["Budget"];?></td>
    <td align="right"><?=$objResult["Used"];?></td>
    <td align="center"><input type="checkbox" name="chkEmail[]" value="<?=$objResult["Email"];?>"></td>
  </tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
<input type="submit" name="btnSave" value="Save">
</form>
</body>
</html>


Code (save.php)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");

	for($i=0;$i<count($_POST["chkEmail"]);$i++)
	{
		if($_POST["chkEmail"][$i] != "")
		{
			$strSQL = "INSERT INTO table_name (Mail) VALUES ('".$_POST["chkEmail"][$i]."')";
			$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");			
		}
	}

	echo "Record Insert.";

mysql_close($objConnect);
?>
</body>
</html>


Go to : PHP Multiple Checkbox






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-03 09:14:37 By : mr.win
 


 

No. 2



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



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

ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2012-09-03 09:14:37
รายละเอียดของการตอบ ::
ขอบคุณครับ ไม่มีวิธีแบบอื่นหรอครับ T_T

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-03 16:17:33 By : veeitdata5
 

 

No. 3



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



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


ช่องเลือกอุปกรณ์ชำรุด จำเป็นต้องติ๊กอย่างน้อย 1 ช่องใช่ไม๊คับ

ถ้าจำเป็น ก็ดักที่ javascript แหละคับ ง่ายที่สุด

เชคที่ตัวแปร ของ checkbox ถ้า lenght < 0 ก็ให้ alert เตือนอะไรขึ้นมาสักอย่าง
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-03 16:30:15 By : cocka
 


 

No. 4



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



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

ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2012-09-03 09:14:37
รายละเอียดของการตอบ ::
code ครับ
หน้า form
Code (PHP)
<html>
<head>
<title>ระบบจัดการหอพัก</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../../css/web.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../../js/jquery-ui-1.8.22.custom.min.js"></script>
<script language="javascript">
function fncSubmit(formRepair){
	fail = fncSubmitRepair(formRepair.chbBed.checked|| formRepair.chbLamp.checked || formRepair.chbWardrobe.checked || 
	formRepair.chbTable.checked || formRepair.chbVanity.checked || formRepair.chbHeater.checked || formRepair.chbFan.
	checked || formRepair.chbAir.checked );
	if (fail == "") return true
	else{ alert(fail);
		return false
	}
}
function fncSubmitRepair(field){ 
	if(field=="") return "คุณยังไม่ได้เลือกอุปกรณ์ซ่อมชำรุด \n"
		return ""
}
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices (Admin.psd) -->
<table width="1024" height="700" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
	<tr>
		<td colspan="3" background="../../images/loginadmin_01.jpg" width="1024" height="210"></td>
	</tr>
	<tr>
		<td width="229" height="420" valign="top" background="../../images/loginadmin_02.jpg" bgcolor="#CCCCCC"><br>
		  <table width="200" border="0" align="center">
		    <tr>
		      <td align="center"><p>ยินดีต้อนรับ<br>
		        คุณ <?php 
						include "../../config/connect_db.php";
						session_start();
						$ses_userid =$_SESSION['ses_userid'];
						$ses_user = $_SESSION['ses_user'];
						if($ses_userid <> session_id() or  $ses_user ==""){
							echo "<script language=\"JavaScript\">";
							echo "alert('ไม่พบเซนชั่น กรุณาเข้าสู่ระบบใหม่.');";
							echo "window.location='/dormitory/user/loginuser.php';";
							echo "</script>";
						} else {
						$result = mysql_query("SELECT * FROM user WHERE User_ID ='$_SESSION[ses_user]' ");
							while ($rs = mysql_fetch_array($result) ) {
								echo $rs['User_Fname'],' ', $rs['User_Lname'], "<br />";
							}
						}
					?>
		        เข้าสู่ระบบข้อมูลหอพัก<br>
	          <a href="JavaScript:if(confirm('คุณจะออกจากระบบนี้หรือไม่ ?')==true){window.location='../../config/checkloginuser.php';}" class="linkweb">ออกจากระบบ</a></p></td>
	        </tr>
		    <tr>
		      <td align="left" class="link"><a href="../indexuser.php" class="linkweb">หน้าหลัก</a></td>
	        </tr>
		    <tr>
		      <td align="left"><a href="../roomnull.php">ข้อมูลห้องว่าง</a></td>
	        </tr>
		    <tr>
		      <td align="left"><a href="../rental/rental.php">ตรวจสอบค่าเช่าห้องพัก</a></td>
	        </tr>
		    <tr>
		      <td align="left"><a href="equipment.php">แจ้งการชำรุดอุปกรณ์</a></td>
	        </tr>
        </table></td>
    <td width="744" height="420" align="center" valign="top" background="../../images/loginadmin_03.jpg" bgcolor="#CCCCCC"><p class="bighand"><br>
    ข้อมูลแจ้งการชำรุดอุปกรณ์</p>
      <form name="form1" method="post" action="">
        <table width="497" border="1" bordercolor="#FF99FF">
          <tr class="smallhand">
            <td width="113" align="center">รหัสแจ้งซ่อม</td>
            <td width="129" align="center">วันที่แจ้งซ่อม</td>
            <td width="79" align="center">รหัสผู้เช่า</td>
            <td width="89" align="center">รายละเอียด</td>
            <td width="53" align="center" bgcolor="#FFFFFF"></td>
          </tr>
          <?php
		  		function thai_date($time){
					global $thai_month_arr;
					$thai_date_return = date("j",$time);
					$thai_date_return.= " ".$thai_month_arr[date("n",$time)];
					$thai_date_return.= " ".(date("Y",$time)+543);
						return $thai_date_return;
				 }
				include "../../config/connect_db.php";
				include "../../js/thaidate.php";
				$strSQL = "SELECT * FROM repair WHERE User_ID = '$_SESSION[ses_user]' ORDER BY Repair_Date DESC; ";
				$result = mysql_query($strSQL);
				while($rs = mysql_fetch_array($result))
				{
		?>
          <tr>
            <td align="center"><?php echo $rs["Repair_ID"]?></td>
            <td align="center"><?php $var_date = $rs["Repair_Date"]; 
									$thai_month_arr = array("0"=>"","1"=>"มกราคม", "2"=>"กุมภาพันธ์", "3"=>"มีนาคม", "4"=>"เมษายน", "5"=>"พฤษภาคม",
									"6"=>"มิถุนายน", "7"=>"กรกฎาคม", "8"=>"สิงหาคม", "9"=>"กันยายน", "10"=>"ตุลาคม", "11"=>"พฤศจิกายน",
									"12"=>"ธันวาคม" );
									 $var_date=strtotime("$var_date"); 
									 $var_date= thai_date($var_date);
									 echo $var_date;
						?></td>
            <td align="center"><?php echo $rs["User_ID"]?></td>
            <td align="center"><a href="rpequipment.php?repair_id=<?php echo $rs["Repair_ID"]?>" class="linkweb">คลิก</a></td>
            <td align="center" bgcolor="#FFFFFF"><?php if ($rs["Repair_Status"] == '1')
																									echo "<img src='../../images/email.png' width='25' height='25'>";
																								else
																									echo "<img src='../../images/email_open.png' width='25' height='25'>";
																					?></td>
          </tr>
          <?php } ?>
        </table>
      </form><p class="bighand">แจ้งซ่อมชำรุดอุปกรณ์
        <?php
			include "../../config/connect_db.php";
			$strSQL = "SELECT user.*, room.* FROM user, room " ;
    		$strSQL .= "WHERE room.Build_No = user.Build_No  AND room.Room_No = user.Room_No AND User_ID = '$_SESSION[ses_user]' ;" ;
			$result = mysql_query ( $strSQL );
			$rs = mysql_fetch_array ( $result )
		?>
      </p>
      <form action="equipmentsave.php" method="post" name="formRepair" id="formRepair" OnSubmit="return fncSubmit(this)">
        <table border="1" bordercolor="#FF99FF">
          <tr>
            <td width="127" align="right">วันที่แจ้ง :</td>
            <td colspan="3"><?php echo thaidate( 'l j F Y', time() ) ; ?></td>
          </tr>
          <tr>
            <td align="right">รหัสผู้แจ้ง :</td>
            <td colspan="3"><?php echo $rs["User_ID"]?></td>
          </tr>
          <tr>
            <td align="right">ชื่อ - นามสกุลผู้แจ้ง :</td>
            <td colspan="3"><?php echo $rs["User_Fname"],' ',$rs["User_Lname"]?></td>
          </tr>
          <tr>
            <td height="24" colspan="4" align="center" valign="top" class="smallhand">กรุณาเลือกอุปกรณ์ชำรุด</td>
          </tr>
          <tr>
            <td align="right">ซ่อมเตียง :</td>
            <td width="90" align="left"><input name="chbBed" type="checkbox" id="chbBed" value="1"></td>
            <td width="113" align="right">ซ่อมหลอดไฟ :</td>
            <td width="90" align="left"><input name="chbLamp" type="checkbox" id="chbLamp" value="1"></td>
          </tr>
          <tr>
            <td align="right">ซ่อมตู้เสื้อผ้า :</td>
            <td align="left"><input name="chbWardrobe" type="checkbox" id="chbWardrobe" value="1"></td>
            <td align="right">ซ่อมโต๊ะ :</td>
            <td align="left"><input name="chbTable" type="checkbox" id="chbTable" value="1"></td>
          </tr>
          <tr>
            <td align="right">ซ่อมโต๊ะเครื่องแป้ง :</td>
            <td align="left"><input name="chbVanity" type="checkbox" id="chbVanity" value="1"></td>
            	<?php include "../../config/connect_db.php";
							if($rs["Build_No"] == "2"){
									echo "<td align='right'>ซ่อมเครื่องทำน้ำอุ่น :</td>";
									echo "<td align='left'><input name='chbHeater' type='checkbox' id='chbHeater' value='1'></td>";
		  echo "</tr>";
									if($rs["Room_Type"] == "F"){
											echo "<tr>";
											echo "<td align='right'>ซ่อมพัดลม :</td>";
											echo "<td align='left'><input name='chbFan' type='checkbox' id='chbFan' value='1'></td>";
									}else{
											echo "<td align='right'>ซ่อมแอร์ :</td>";
											echo "<td align='left'><input name='chbAir' type='checkbox' id='chbAir' value='1'></td>";
											echo "</tr>";
									}
							}
          ?>
          <tr>
            <td align="right">รายละเอียดเพิ่มเติม :</td>
            <td colspan="3"><input name="textDetailetc" type="text" id="textDetailetc" size="50" maxlength="30"></td>
          </tr>
          <tr>
            <td colspan="4" align="center"><input type="submit" name="butRepair" id="butRepair" value="แจ้งซ่อม"></td>
          </tr>
        </table>
      </form>
<p class="bighand">&nbsp; </p></td>
		<td background="../../images/loginadmin_04.jpg" width="25" height="420"></td>
  </tr>
	<tr bgcolor="#CCCCCC">
		<td width="1024" height="70" colspan="3" background="../../images/loginadmin_05.jpg"></td>
	</tr>
</table>
<!-- End Save for Web Slices -->
</body>
</html>
<?php
	mysql_close($conn);
?>



หน้า code save
Code (PHP)
<?php 
	include "../../config/connect_db.php";
	session_start();
	$ses_userid =$_SESSION['ses_userid'];
	$ses_user = $_SESSION['ses_user'];
	if($ses_userid <> session_id() or  $ses_user ==""){
		echo "<script language=\"JavaScript\">";
		echo "alert('ไม่พบเซนชั่น กรุณาเข้าสู่ระบบใหม่.');";
		echo "window.location='/dormitory/user/loginuser.php';";
		echo "</script>";
	}
?>
<html>
<head>
<title>ระบบจัดการหอ</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../../css/web.css" rel="stylesheet" type="text/css">
<link href="../../css/ui-lightness/jquery-ui-1.8.22.custom.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices (Admin.psd) -->
<table width="1024" height="700" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
	<tr>
		<td colspan="3" background="../../images/loginadmin_01.jpg" width="1024" height="210"></td>
	</tr>
	<tr>
		<td background="../../images/loginadmin_02.jpg" width="25" height="420"></td>
		<td width="974" height="420" align="center" background="../../images/loginadmin_03.jpg">
			<?php
				include "../../config/connect_db.php";
				if($_POST['textDetailetc'] == ""){
					$repairetc = "0";
					$detailetc = "-";
				}else{
					$repairetc = "1";
					$detailetc = $_POST["textDetailetc"];
				}
				$strSQL = "INSERT INTO repair (User_ID, Repair_Date, Repair_Bed, Repair_Lamp, Repair_Wardrobe, Repair_Table, Repair_Vanity,
				Repair_Heater, Repair_Fan, Repair_Air, Repair_Etc, Detail_Etc, Repair_Status) ";
				$strSQL .= "VALUES ('$_SESSION[ses_user]', NOW(), '$_POST[chbBed]', '$_POST[chbLamp]', '$_POST[chbWardrobe]', 
				'$_POST[chbTable]', '$_POST[chbVanity]', '$_POST[chbHeater]', '$_POST[chbFan]', '$_POST[chbAir]',  '$repairetc', 
				'$detailetc', '1'); ";
						echo "<p class='bighand'>ระบบทำการบันทึกไว้เรียบร้อยแล้ว<br>กรุณารอสักครู่</p><br>";
						echo "<img src='../../images/line.gif' width='576' height='19'>";
						echo "<meta http-equiv='refresh' content='20;URL= /dormitory/user/repair/equipment.php' />";
				mysql_query( $strSQL, $conn )
					or die ( "ไม่สามารถส่งข้อมูลการแจ้งซ่อมได้." . mysql_error()) ;
            ?>        
        </td>
		<td background="../../images/loginadmin_04.jpg" width="25" height="420"></td>
	</tr>
	<tr>
		<td colspan="3" background="../../images/loginadmin_05.jpg" width="1024" height="70"></td>
	</tr>
</table>
<!-- End Save for Web Slices -->
</body>
</html>
<?php
	mysql_close($conn);
?>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-03 16:31:40 By : veeitdata5
 


 

No. 5



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



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

ตอบความคิดเห็นที่ : 3 เขียนโดย : cocka เมื่อวันที่ 2012-09-03 16:30:15
รายละเอียดของการตอบ ::
สำหรับฟ้องใก้ติกอย่างหน้อง 1 ช่องได้แล้วครับ ติดตรงที่ check box ถ้าไม่ติกก็ฟ้อง error ครับ แต่ฐานข้อมูลเข้า เพราะผมใช้แบบค่าปรียาย 0

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-03 16:33:14 By : veeitdata5
 

   

ค้นหาข้อมูล


   
 

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