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 > พอใส่ข้อมูลแล้วกดค้นหา error แต่ถ้าไม่ใส่ข้อมูลในช่องค้นหา ไม่ error



 

พอใส่ข้อมูลแล้วกดค้นหา error แต่ถ้าไม่ใส่ข้อมูลในช่องค้นหา ไม่ error

 



Topic : 114677



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



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




คือถ้าหากไม่ใส่ข้อมูลในช่องค้นหา แล้วกดค้นหาก็จะปกติ

1

หากใส่ข้อมูลที่ต้องการค้นหา แล้วกดค้นหา กลับขึ้น Error

2

ไม่ทราบว่าโค๊ดผิดตรงไหนคับ
Code (PHP)
<form d="form1" name="form1" method="post">
			<tr class="menu3">
			  <td height="33">&nbsp;</td>
			  <td>&nbsp;</td>
			  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;หมายเลข</td>
			  <td><input name="txt_c_number" type="text" id="txt_c_number" size="11" onKeyUp="checkNumber1(this)" /></td>
			  <td>&nbsp;&nbsp;ชื่อ</td>
			  <td><input name="txt_c_name" type="text" id="txt_c_name" size="15" ></td>
			  <td>&nbsp;&nbsp;&nbsp;&nbsp;เบอร์โทร</td>
			  <td><input name="txt_c_phone1" type="text" id="txt_c_phone1" size="15" ></td>
			  <td colspan="2">&nbsp;</td>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			  </tr>
			<tr>
			  <td height="16">&nbsp;</td>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			  <td colspan="3">&nbsp;</td>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			  <td colspan="2">&nbsp;</td>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			  </tr>
			<tr>
			  <td height="35">&nbsp;</td>
			  <td colspan="11"><div align="center">
			    <input type="submit" name="Submit" value=" Search " />
			    </div></td>
			  </tr>
			</form>
			
			<tr>
			  <td height="34" class="style2">&nbsp;</td>
			  <td colspan="10" rowspan="4"><table border="0" width="100%" id="table50" cellspacing="0" cellpadding="0">
                <tr class="menu3">
                  <td width="58" height="25">&nbsp;</td>
                  <td width="116">&nbsp;</td>
                  <td width="112">&nbsp;</td>
                  <td width="85">&nbsp;</td>
                  <td width="187" height="25">&nbsp;</td>
                  <td width="26" height="25">&nbsp;</td>
                  <td width="22" height="25">&nbsp;</td>
                  <td width="64" height="25">&nbsp;</td>
                  <td height="25" colspan="2">&nbsp;</td>
                  <td width="35" height="25">&nbsp;</td>
                </tr>
                <tr class="menu3">
                  <td height="25" colspan="11"><table width="100%" border="1" cellpadding="0" cellspacing="0">
                    <tr  background="../image/menu_about.jpg">
                      <th width="7%" height="20" scope="col">No.</th>
                      <th width="16%" scope="col">User Id</th>
                      <th width="17%" scope="col">Nickname</th>
                      <th width="7%" scope="col">Title</th>
                      <th width="53%" scope="col">Name - Lastname</th>
                      </tr>
                    </table></td>
                </tr>
              <? 
			$page = $_POST['page']; 
			//$search=$_POST['search']; 
			if( $page!=0) 
			$page-=1; 
			$OnePage=15;
		// if($_POST[Submit]){
			// if($_POST[Submit]){
				 if($_POST[txt_c_number] != ''){
					$condition3 = "and c_number like '%$txt_c_number%'";
			 	
					
				}
				if($_POST[txt_c_name] != ''){
					$condition1 = "and c_name like '%$txt_c_name%'";
				
					
				}
				if($_POST[txt_c_phone1] !=''){
					$condition2 = "and c_phone1 like '%$txt_c_phone1%'";
					
				}
				$sql_condition = $condition1.' '.$condition2.' '.$condition3;
				
			 $i = 0;
			  $sql="SELECT * FROM customer" ; 
						
						 $sql2 = $sql.' '.$sql_condition;
			 
		//*** เริ่มแบ่งหน้า ****//   
       	 $QueryCount=mysql_query($sql2);//$result=mysql_query($sql);  
          
                
        $AllPage=mysql_num_rows($QueryCount); 
        $totalrow=$AllPage; 
        $p=1; 
   		while ( $AllPage > $OnePage) { 
       	 	$AllPage-=$OnePage; 
       	 	$p++; 
         } 
        $AllPage=$p;  ///  all of page 
        $result = mysql_query($sql2." LIMIT ". $OnePage*$page." ,". $OnePage); 
        //*** เริ่มแบ่งหน้า ****// 
		
			  while( $data=mysql_fetch_array($result) ){ $i++;
			
			  ?>
                <tr class="menu4" >
            <td height="30"><div align="center"><? echo $i;?></div></td>
            <td><div align="center"><a href="select_register_course.php?per_user_id=<? echo $data[c_number];?>">
              <? 	 echo $data[c_number]; ?>
            </a></div></td>
            <td><div align="center"><a href="select_register_course.php?per_user_id=<? echo $data[U_ID];?>">
              <? 	 echo $data[c_name]; ?>
            </a></div></td>
            <td height="30"><div align="center">
              <? 	 echo $data[c_phone1]; ?>
            </div></td>
            <td height="30"><div align="center">
              <? 	
				    if ($data[c_brand] =="1"){echo "Acer";}
	 					else if ($data[c_brand]=="2"){echo "Asus";}
							 else if ($data[c_brand]=="3"){echo "DELL"; }
							 else if ($data[c_brand]=="4"){echo "HP"; }
							 else if ($data[c_brand]=="5"){echo "Compaq"; }
							 else if ($data[c_brand]=="6"){echo "Lenovo"; }
							 else if ($data[c_brand]=="7"){echo "Samsung"; }
							 else if ($data[c_brand]=="8"){echo "Toshiba"; }
							 else if ($data[c_brand]=="9"){echo "Gigabyte"; }
							 else if ($data[c_brand]=="10"){echo "Wio"; }
							 else if ($data[c_brand]=="11"){echo "Canon"; }
							 else if ($data[c_brand]=="12"){echo "อื่นๆ"; }
							
							 ?>
            </div></td>
            <td height="30"><div align="center">
              <? 	 echo $data[c_generation]; ?>
            </div></td>
            <td height="30"><div align="center">
              <? 	 echo $data[c_problem]; ?>
            </div></td>
            <td height="30" colspan="3"><div align="center">
              <? 	
				    if ($data[c_status] =="1"){echo "รอซ่อม";}
	 					else if ($data[c_status]=="2"){echo "เสนอราคา";}
							 else if ($data[c_status]=="3"){echo "กำลังซ่อม"; }
							 else if ($data[c_status]=="4"){echo "ส่งต่อ/เคลม"; }
							 else if ($data[c_status]=="5"){echo "กลับจากเคลม"; }
							 else if ($data[c_status]=="6"){echo "ซ่อมเสร็จ"; }
							 else if ($data[c_status]=="7"){echo "ยกเลิกซ่อม"; }
							 else if ($data[c_status]=="8"){echo "ปิดงานซ่อม"; }
							 
							
							 ?>
            </div></td>
            <td width="5"></td>
          </tr>
                <? }//end while
			//	}?>
                
                <tr class="menu5">
                  <td height="30" colspan="10"> <p>&nbsp;
                    </p>
                    <p><div align="center" ><font size="4" color="#FF0000"><b>
                      <? 
				if($i==0)
						echo 'ไม่มีข้อมูลที่ท่านต้องการ';
				?></b></font></div>
                    </p><br />
                     <!-- แบ่งหน้า --> 
<div align="right"> 
      
     <form name="PageForm" method="post" action="">
                <div align="right">
                  <?  
                        
                      if($AllPage>1) {  /// has  page  dropdown?>
                  <input name="id_group" type="hidden" id="id_group" value="<?=$id_group?>" />
                  <strong>หน้า</span></strong><span class="style2">&nbsp;</span>
                  <select name="page" class="input_left" id="page" onchange="document.PageForm.submit(); ">
                    <? for ($i=1;$i<=$AllPage;$i++) {?>
                    <option  <? if($page+1==$i) echo " selected ";?> value="<?=$i?>" >Page
                      <?=$i?>
                      </option>
                    <? } ?>
                  </select>
                  <? }  /// has page  dropdown ?>
                </div>
                <input type="hidden" name="txt_number2" value="<?=$_POST[txt_number]?>" />
                <input type="hidden" name="txt_nickname" value="<?=$_POST[txt_nickname]?>" />
                <input type="hidden" name="txt_name" value="<?=$_POST[txt_name]?>" />
                <input type="hidden" name="Submit2" value="<?=$_POST[Submit]?>" />
                 </form> 


ขอบคุณคับ



Tag : PHP, CakePHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-02-25 13:19:48 By : wita View : 759 Reply : 6
 

 

No. 1

Guest


Code (PHP)
$sql2 = $sql.' '.$sql_condition;


echo $sql2; แสดงค่า sql ออกมาว่าค่าที่ได้คืออะไร แล้วลองนำไปรันที่ phpmyadmin ดูครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-02-25 14:14:20 By : WiTT
 


 

No. 2



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



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


ตอบความคิดเห็นที่ : 1 เขียนโดย : WiTT เมื่อวันที่ 2015-02-25 14:14:20
รายละเอียดของการตอบ ::
มันขึ้นแบบนี้ครับ

Code (PHP)
ผิดพลาด
คำค้น SQL: เอกสารอ้างอิง

SELECT * 
FROM customer
AND c_name LIKE  '%นายเอ%'
LIMIT 0 , 30

MySQL แสดง: เอกสารอ้างอิง

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and c_name like '%นายเอ%' 
LIMIT 0, 30' at line 1 


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-02-25 15:07:49 By : wita
 

 

No. 3



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



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

ผิดตรง
Code (PHP)
if($_POST[txt_c_number] != ''){
069.
$condition3 = "and c_number like '%$txt_c_number%'";
070.
 
071.
 
072.
}
073.
if($_POST[txt_c_name] != ''){
074.
$condition1 = "and c_name like '%$txt_c_name%'";
075.
 
076.
 
077.
}
078.
if($_POST[txt_c_phone1] !=''){
079.
$condition2 = "and c_phone1 like '%$txt_c_phone1%'";
080.
 
081.
}
082.
$sql_condition = $condition1.' '.$condition2.' '.$condition3;
083.
 
084.
$i = 0;
085.
$sql="SELECT * FROM customer" ;
086.
 
087.
$sql2 = $sql.' '.$sql_condition;


เมื่อค่าออกมาคือ

Code (SQL)
SELECT * FROM customer and c_name like '%$txt_c_name%' and c_phone1 like '%$txt_c_phone1%'  and c_phone1 like '%$txt_c_phone1%'


ไม่มี where จ้าาาา แล้ว and ก็ดึงโผล่มาตัวแรกเลย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-02-25 15:09:07 By : progamer2000
 


 

No. 4



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



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

Code (PHP)
				 if($_POST[txt_c_number] != ''){
					$condition .= "AND c_number like '%$txt_c_number%'";
			 	
					
				}
				if($_POST[txt_c_name] != ''){
					$condition .= "AND c_name like '%$txt_c_name%'";
				
					
				}
				if($_POST[txt_c_phone1] !=''){
					$condition .= "AND c_phone1 like '%$txt_c_phone1%'";
					
				}
				
			 $i = 0;
			  $sql="SELECT * FROM customer where code <> 0 "; 
                          $sql2 = $sql.$condition;
			  $QueryCount=mysql_query($sql2);			




ประวัติการแก้ไข
2015-02-25 15:13:28
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-02-25 15:11:33 By : progamer2000
 


 

No. 5



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



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


085.$sql="SELECT * FROM customer" ;

แก้เป้น

085.$sql="SELECT * FROM customer where 1 " ;

กรณีนี้ใช้เมื่อ ถ้าไม่ ใส่ condition จะเอาทั้งหมด
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-02-25 15:52:14 By : Chaidhanan
 


 

No. 6



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



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


ตอบความคิดเห็นที่ : 5 เขียนโดย : Chaidhanan เมื่อวันที่ 2015-02-25 15:52:14
รายละเอียดของการตอบ ::
ได้แอล้วครับ ของคุณทุกๆท่านครับ แค่ใส่ where 1

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-02-25 17:48:04 By : wita
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : พอใส่ข้อมูลแล้วกดค้นหา error แต่ถ้าไม่ใส่ข้อมูลในช่องค้นหา ไม่ 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 05
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 อัตราราคา คลิกที่นี่