<?php include("connDB.php"); // คำสั่ง SQL ที่ใช้ในการเลือกข้อมูลที่อยู่ในฐานข้อมูลกลับมา (เรียงตามลำดับ ID) $result = mysql_query("select * from listfood "); /* ในลูปด้านล่าง เทียบได้กับการดึงข้อมูลมาทีละ 1 Record เพื่อนำมาแสดงผลทางหน้าจอ */ while($dbarr = mysql_fetch_array($result)) { ?> <tr> <td width="5%" bgcolor="#CCCCFF" align="center"><?php echo $dbarr['listfood_id'] ; ?></td> <td width="20%" bgcolor="#CCCCFF" align="center"><?php echo $dbarr['listfood_name'] ; ?></td> <td width="5%" bgcolor="#CCCCFF" align="center"><center><a href="100001edit.php?id=<?=$dbarr['listfood_id'];?>">แก้ไข</a></center></td> <td width="5%" bgcolor="#CCCCFF" align="center"><center><a href="100001delete.php?id=<?=$dbarr['listfood_id'];?>" OnClick="return Conf(this)">ลบ</a></center></td> </tr> </td>
<?php include "connDB.php"; $result = mysql_query("select * from listfood where listfood_id='$id'"); $dbarr = mysql_fetch_array($result) ; ?> <td width="715" align="center" valign="top"><p> </p> <form action="100001edit_in.php" method="post"> <table width="490" border="1"> <tr> <td width="111" align="center"><strong>รหัสอาหาร</strong></td> <td width="369"><label> <input name="listfood_id" type="text" value ="<? echo "$id";?>" size="30" style="width: 227px" maxlength="100"> </label></td> </tr> <tr> <td align="center"><strong>รายการอาหาร</strong></td> <td><label> <input name="listfood_name" type="text" size="5" value ="<?=$dbarr['listfood_name'];?>" maxlength="5"> </label></td> </tr> <tr> <td colspan="2" align="center"><label></label> <input type="submit" name="Submit" value=" แก้ไข "> <input name="cancle" type="submit" id="cancle" value="ยกเลิก"onClick="document.location.href='p1000.php?show=OK'"></td> </tr> </table> </form>
<form name="form1" method="post" action=""> <?php $hostname = "localhost"; $user = "root"; $password = "root"; $dbname = "dbproject"; $tblname = "listfood"; mysql_connect($hostname, $user, $password) or die("ติดต่อฐานข้อมูลไม่ได้"); mysql_select_db($dbname) or die("เลือกฐานข้อมูลไม่ได้") ?> <?php // คือใช้คำสั่ง SQL ให้ทำการ UPDATE ค่าเข้าไปใหม่ ณ ตำแหน่ง Record ที่มีค่า ID เป็นค่าที่ได้รับมา $sql="UPDATE $tblname set listfood_id='$listfood_id' , listfood_name='$listfood_name' WHERE listfood_id = '$id'"; $result = mysql_query($sql); if($result) { echo "<center> <table border=\"1\" > <tr> <td height=\"136\"> <center> แก้ไขข้อมูลสำเร็จ <br><br> <font size=\"4\"><a href=\"index.php\">กลับหน้าหลัก</a></font> </center> </td> </tr> </table> </center>"; } else { echo "<center> <table border=\"1\"> <tr> <td height=\"136\" bgcolor=\"#FFCCFF\"> <center> การแก้ไขข้อมูลล้มเหลว !!<br><br> <font size=\"4\"><a href=\"100001edit.php\">กลับ</a></font> </center> </td> </tr> </table> </center>"; } ?> </form>
Quote:$result = mysql_query($sql);
<?php $hostname = "localhost"; $user = "root"; $password = "root"; $dbname = "dbproject"; $tblname = "listfood"; mysql_connect($hostname, $user, $password) or die("ติดต่อฐานข้อมูลไม่ได้"); mysql_select_db($dbname) or die("เลือกฐานข้อมูลไม่ได้") ?> <?php // คือใช้คำสั่ง SQL ให้ทำการ UPDATE ค่าเข้าไปใหม่ ณ ตำแหน่ง Record ที่มีค่า ID เป็นค่าที่ได้รับมา $sql="UPDATE $tblname set listfood_id='".$_POST['listfood_id']."' , listfood_name='".$_POST['$listfood_name']."' WHERE listfood_id = '".$_POST['$id']." '"; $result = mysql_query($sql); if($result) { echo "<center> <table border=\"1\" > <tr> <td height=\"136\"> <center> แก้ไขข้อมูลสำเร็จ <br><br> <font size=\"4\"><a href=\"index.php\">กลับหน้าหลัก</a></font> </center> </td> </tr> </table> </center>"; } else { echo "<center> <table border=\"1\"> <tr> <td height=\"136\" bgcolor=\"#FFCCFF\"> <center> การแก้ไขข้อมูลล้มเหลว !!<br><br> <font size=\"4\"><a href=\"100001edit.php\">กลับ</a></font> </center> </td> </tr> </table> </center>"; } ?>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง