<center><table width="744" border="0"> <tr> <td width="62" height="73"> </td> <td width="56"> </td> <td width="10"> </td> <td width="496"> <?php ini_set('display_errors', 2); error_reporting(~0); $strKeyword = null; if(isset($_POST["txtKeyword"])) { $strKeyword = $_POST["txtKeyword"]; } ?> <?php ini_set('display_errors', 2); error_reporting(~0); $strKeyword1 = null; if(isset($_POST["txtKeyword1"])) { $strKeyword = $_POST["txtKeyword1"]; } ?> <form name="frmSearch" method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>"> <table width="471" border="1"> <tr> <th width="461"><center> <input name="txtKeyword" type="text" id="txtKeyword" size="20" value="<?php echo $strKeyword;?>"> <input name="txtKeyword1" type="text" id="txtKeyword1" size="20" value="<?php echo $strKeyword1;?>"> <input type="submit" value="ตรวจสอบ"></th> </tr> </table> </form> </td> <td width="98"> </td> </tr> </table></center> <p> </p> <form> <?php $serverName = "localhost"; $userName = "root"; $userPassword = ""; $dbName = "project"; $conn = mysqli_connect($serverName,$userName,$userPassword,$dbName); $sql = "SELECT * FROM salary1 WHERE per_id LIKE '%".$strKeyword."%' or per_name LIKE '%".$strKeyword1."%' "; $query = mysqli_query($conn,$sql); ?> <table width="850" border="1" align="center"> <tr> <th width="83"> <div align="center">รหัสพนง.</div></th> <th width="157"> <div align="center">ชื่อ-นามสกุล</div></th> <th width="69"> <div align="center">เดือน</div></th> <th width="50"> <div align="center">ปี</div></th> <th width="78"> <div align="center">เงินเดือน</div></th> <th width="71"> <div align="center">OT</div></th> <th width="71"> <div align="center">เบี้ยขยัน</div></th> <th width="57"> <div align="center">ส.ป.ส.</div></th> <th width="83"> <div align="center">คงเหลือ</div></th> <th width="83"> <div align="center">สลิปเงินเดือน</div></th> <th width="31"><div align="center">แก้ไข</div></th> <th width="30"><div align="center">ลบ</div></th> </tr> <?php while($result=mysqli_fetch_array($query,MYSQLI_ASSOC)) { ?> <tr> <td><div align="center"><?php echo $result["per_id"];?></div></td> <td><div align="center"><?php echo $result["per_name"];?></div></td> <td><div align="center"><?php echo $result["sa_month"];?></div></td> <td><div align="center"><?php echo $result["sa_year"];?></div></td> <td align="right"><?php echo $result["sa_salary"];?></td> <td align="right"><?php echo $result["sa_ot"];?></td> <td align="right"><?php echo $result["sa_diligence"];?></td> <td align="right"><?php echo $result["sa_insurance"];?></td> <td width="83"align="right"><?php echo $result["sa_sum"];?></td> <td width="31" align="center"><a href="slip.php?id=<?php echo $result['id']; ?>">สลิป</a></td> <td width="31" align="center"><a href="edit_salary.php?id=<?php echo $result['id']; ?>">แก้ไข</a></td> <td width="30" align="center"><a href="delete_salary.php?id=<?php echo $result["id"];?>">ลบ</a></td> </tr> <?php } ?> </table> <p> <?php mysqli_close($conn); ?>
<html> <head> <title>ThaiCreate.Com PHP & MySQL Tutorial</title> </head> <body> <form name="frmSearch" method="post" action="<?=$_SERVER['SCRIPT_NAME'];?>"> <table width="599" border="1"> <tr> <th>เดือน <input name="txt1" type="text" id="txt1" value="<?=$_POST["txt1"];?>"> ปี <input name="txt2" type="text" id="txt2" value="<?=$_POST["txt2"];?>"> <input type="submit" value="Search"></th> </tr> </table> </form> <? $objConnect = mysql_connect("localhost","root","") or die("Error Connect to Database"); $objDB = mysql_select_db("project"); $strSQL = "SELECT * FROM salary1 WHERE 1 "; if($_POST["txt1"] != "") { $strSQL .= " AND (sa_month LIKE '%".$_POST["txt1"]."%')"; } if($_POST["txt2"] != "") { $strSQL .= " AND (sa_year LIKE '%".$_POST["txt2"]."%')"; } $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> </tr> <? while($objResult = mysql_fetch_array($objQuery)) { ?> <tr> <td><div align="center"><?=$objResult["per_id"];?></div></td> <td><?=$objResult["per_name"];?></td> <td><?=$objResult["sa_month"];?></td> <td><div align="center"><?=$objResult["sa_year"];?></div></td> <td align="right"><?=$objResult["sa_salary"];?></td> </tr> <? } ?> </table> <? mysql_close($objConnect); ?> </body> </html>
if(isset($_POST["txtKeyword1"])) { $strKeyword = $_POST["txtKeyword1"]; // ประกาศตัวแปรผิดหรือเปล่า }
$strKeyword = isset($_POST['txtKeyword']) ? $_POST['txtKeyword'] : null; //ถ้าไม่ได้ set ให้เท่ากับ null $strKeyword1 = isset($_POST['txtKeyword1']) ? $_POST['txtKeyword1'] : null; //ถ้าไม่ได้ set ให้เท่ากับ null
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง