|  | 
	                
  
    | 
	 
        รบกวนหนอยนะคับเนื่องจากทำการแก้ไขและลบไม่ได้คับรบกวนดูโค้ดให้หน่อยคับว่าผิดตรงไหนคับ. ..ไม่มีการขึ้น error เลยคับผมหาไม่เจอคับ     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | โค้ดนะคับ Code (PHP)
 
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include ("connet.php");
?>
  <?
$page=$_GET[page];
if ($page==""){
$page=1;
}
$each=5;
$sql_admin = "SELECT * FROM admin;";
$result_admin = mysql_query($sql_admin);
$totals=mysql_num_rows($result_admin);
$totalpages=ceil($totals/$each);
$goto=($page-1)*$each;
$sql_admin="SELECT * FROM admin ORDER BY admin_id DESC limit $goto,$each;";
$result_admin=mysql_query($sql_admin);
?>
<form method="post" action="admin_action.php">
<input type="hidden" name="do" value="add" />
  <table width="534" border="0" align="center">
    <tr bgcolor="#E0EEEE">
      <th width="522" align="right" scope="col">::<img src="20121116050143551_easyicon_cn_32.png" alt="" width="20" height="20" /> เพิ่มผู้ดูแลระบบ::</th>
    </tr>
  </table>
  <table width="534" border="0" align="center">
    <tr>
      <td width="151" align="right">E-mail ::</td>
      <td width="373"><label for="email"></label>
      <input type="text" name="email" id="email" /></td>
    </tr>
    <tr >
      <td align="right">Password ::</td>
      <td><label for="password">
        <input type="password" name="password" id="password" />
      </label></td>
    </tr>
    <tr >
      <td align="right">ชื่อ-นามสกุล</td>
      <td><label for="name">
        <input type="text" name="name" id="name" />
      </label></td>
    </tr>
    <tr align="right">
      <td colspan="2" align="center"><input type="submit" name="button" id="button" value="เพิ่มผู้ดูแลระบบ" />
        <input type="reset" name="button2" id="button2" value="ยกเลิก" />
      <input type="hidden" name="id_admin" value="<?=$total; ?>" /></td>
    </tr>
  </table></form>
<table width="591" border="0" align="center" cellpadding="2" cellspacing="0">
   
    <tr align="center" bgcolor="#E0EEEE">
      <td width="91">ลำดับที่ </td>
      <td width="139">ชื่อผู้ใช้ </td>
      <td width="127">รหัสผ่าน </td>
       <td width="127">ชื่อ - นามสกุล </td>
      <td width="132">รายละเอียด</td>
      <td width="59">แก้ไข</td>
      <td width="98">ลบ</td>
    </tr>
    <?
	  $strRow=0;
$strRow=($each*$page)-$each;//การกำหนดลำดับสินค้า
while ($cs = mysql_fetch_array($result_admin)){
$strRow++;//ลำดับเพิ่มทีละ 1 นั้นเอง
$sql = "select * from admin where admin_id='".$cs['admin_id']."'";
$dbquery = mysql_query($sql);
$num_rows = mysql_num_rows($dbquery);
?>
    <tr align="center">
     
      <td><? echo $strRow ?></td>
      <td><? echo $cs['email'] ?></td>
      <td><? echo $cs['password'] ?></td>
        <td><? echo $cs['name'] ?></td>
     
      
       <td align="center"><a href="showadmin.php?ty=<?=$cs['logname'] ?>"><img src="20121116050309842_easyicon_cn_128.png" alt="" width="20" height="20" /></a></td>
       
      <td><a href ="admin_action.php?do=frmedit&id=<? echo $$cs['admin_id'] ?>"><img src="20121116050301729_easyicon_cn_80.png" alt="" width="20" height="20" /></a></td>
      
      <td align="center"><a href="admin_action.php?do=delete&id=<? echo $cs['admin_id'] ?>"><img src="20121116050436121_easyicon_cn_128.png" alt="" width="20" height="20" /></a></td>
    </tr>
     <?
  }
  ?> 
  
 
    <tr align="left">
<td colspan="4">รายการ <?=$totals?> หน้า :
  <? //Code ใช้ เมื่อ จำนวนหน้ามากกว่า 1 หน้า
if($totalpages>1) {
for ($i=1;$i<=$totalpages;$i++){
if($i==$page) {
echo "<b>หน้า $page </b>";
} else {
echo " | <a href=\"admin.php?page=$i\">$i</a> ";
}
}
}
?>
</td>
</table>
 ส่วนนี้เป็นหน้า action คับ
 Code (PHP)
 
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include "connet.php";
if ($_POST['do']=="add"){
	$email=$_POST['email'];
	$password=$_POST['password'];
	$name=$_POST['name'];
	$tel=$_POST['tel'];
	
	$sql="select * from admin where email='$email'";//ส่วนใหญ่ผิดบรรทัดนี้
	$query = mysql_query($sql);
	$result = mysql_fetch_array($query);
	
	if($result){
		echo "<script language='javascript'>";
		echo "alert('E-mail นี้มีอยู่ในระบบแล้ว');";
		echo "window.location='admin.php';";
		echo "</script>";
	}else{
		$sql_add = "INSERT INTO admin (email,password,name) VALUES ('$email','$password','$name');";
		$result_add=mysql_query($sql_add) or die(mysql_error());
		
		echo "<script language='javascript'>";
		echo "alert('เพิ่มข้อมูลผู้ดูแลระบบเรียบร้อย');";
		echo "window.location='admin.php';";
		echo "</script>";
		}
	
	
	}elseif ($_POST['do']=="delete"){
		$sql="DELETE FROM admin WHERE email='$_POST[id]';";
		$result=mysql_query($sql);
		if($result){
		echo"ระบบได้ทำการลบข้อมูลผู้ดูแลระบบเรียบร้อยแล้ว $result_del";
			echo"<meta http-equiv='refresh' content='2;url=indexadmin.php'>";
		}else{
			echo"ไม่สามารถลบข้อมูลผู้ดูแลระบบได้";
		}
	
	
	}elseif ($_POST['do']=="frmedit"){//ต้องมีการโหลด From ขึ้นมาใหม่...ถ้า ['do']=="frmedit" จริง มันจะใช้คำสั่ง$sql="SELECT * FROM tbcategory WHERE catid =$_POST[id]"; คือเรียกขึ้นม่า 1 record 
			
			$sql="SELECT * FROM admin WHERE email =$_POST[id]";//เมื่อคลิก ปุ่มแก้ไขมันจะส่งค่าไป
			$result=mysql_query($sql);
			$dbarr=mysql_fetch_array($result);
?>
<form method="post" action="admin_action.php?do=edit">
  <table width="534" border="0" align="center">
    <tr align="right" >
      <td width="151">รหัสผู้ดูแลระบบ::</td>
<td align="left"><?=$dbarr['admin_id']; ?></td>
    </tr>
    <tr >
      <td align="right">Login ::</td>
      <td><label for="email"></label>
      <input name="email" type="text" id="email"  value="<?=$dbarr['email']; ?>"/></td>
    </tr>
    <tr >
      <td align="right">Password ::</td>
      <td><label for="password"></label><input name="password" type="text" id="password"  value="<?=$dbarr['password']; ?>"/></td>
    </tr>
    <tr >
      <td align="right">ชื่อ-นามสกุล</td>
      <td><label for="name">
      </label><input name="name" type="text" id="name"  value="<?=$dbarr['name']; ?>"/></td>
    </tr>
    <tr align="right">
      <td colspan="2" align="center">
      <div align="center">
       <input type="hidden" name="id" value="<?=$dbarr['admin_id'];?>">
      <input type="submit" name="button" id="button" value="บันทึก" />
        <input type="reset" name="button2" id="button2" value="ยกเลิก" />
      </div></td>
    </tr>
  </table>
</form>
<?
}elseif ($_POST['do']=="edit"){
	$email=$_POST['email'];
	$password=$_POST['password'];
	$name=$_POST['name'];
	
	
	
	$sql_update = "UPDATE admin SET email='$email',password='$password',name='$name' WHERE admin_id='$_POST[id]'";
$reslut_update=mysql_query($sql_update) or die(mysql_error());
	
	if($result_update){
		echo"ระบบได้ทำการแก้ไขข้อูลผู้ดูแลระบบเรียบร้อยแล้ว";
		echo "<meta http-equiv='refresh' content='2;url=admin.php'>";
	}else{
		echo"ไม่สามารถแก้ไขข้อมูลได้";
	}
}
?>
 
 
 Tag : PHP, MySQL, HTML/CSS, JavaScript, jQuery, CakePHP
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2012-12-12 21:09:45 | By :
                          มานะ | View :
                          964 | Reply :
                          11 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ส่วนตรงนี้เป็น SQL คับ 
  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-12-13 11:32:11 | By :
                            มานะ |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | แก้แล้วก้อยังไม่ได้คับไม่รู้ทำยังไงแล้วคับ. .เครียดมาก 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-12-13 11:44:36 | By :
                            มานะ |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ลองเอานี่ไปใช้ดูนะครับ Code (PHP)
 
 <?php 
include("../config.php") ;
		$submit = $_POST["cmdsubmit"];
		$xxx = $_POST["xxx"];
		$id = $_POST["id"];
	
/* end of add */
			$sql[0] = "update ชื่อตาราง set xxx ='$xxx' where id='$id' ";
		
       for($i=0;$i<1;$i++) {
      $result = mysql_query($sql[$i]) or die("Err program");
       }
if($result) {
			echo "<script>alert('รายละเอียดของคุณ ได้ถูกบันทึกใหม่แล้ว')</script>"; 
echo "<script>window.close();</script>";
		}
?>
 
 ปล. ไม่ได้อย่าโกรธกันนา ผมก็มือใหม่มาก
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-12-13 12:28:32 | By :
                            creativegu |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | งง นิดหน่อยคับอธิบายจะตัวแปลที่มีได้ไหมคับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-12-13 19:15:03 | By :
                            มานะ |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ที่ให้ไปเป็นโคด action  สำหรับแก้ไขน่ะครับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-12-13 22:13:33 | By :
                            creativegu |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ก็รับค่ามาจากฟอร์มแล้วก็ทำการแก้ไขหลักๆก็คือเพิ่มฟิลด์ที่รับมาตรง $id = $_POST["id"]; 
 แล้วก็ไปเพิ่มตรงส่วนที่จะเก็บลงตาราง แล้วก็เรีบง number ไปจนครบที่ต้องก่าร
 $sql[0] = "update ชื่อตาราง set ชื่อฟิลด์ ='$ค่าที่รับมา' where id='$id' ";
 $sql[2] = "update ชื่อตาราง set ชื่อฟิลด์ ='$ค่าที่รับมา' where id='$id' ";
 
 
 สุดท้ายก็ตรงนี้
 
 for($i=0;$i<1;$i++) {
 
 ตรงเลข 1 น่ะครับต้อง +1 จากฟิล์ที่ต้องแก้ไขเสมอ สมมุติว่ามีทั้งหมด 5 ฟิลด์ ตรงเลข 1 ก็ต้องเป็น 6 คือบวกไปอีกหนึ่ง
 
 งงมั้ยครับ
 
 พอดีผมก็หัดเขียนมาได้ไม่นานนะครับโคดส่วนมากก็แกะจากในนี้แหละครับ
 
 |  
              | 
 ประวัติการแก้ไข
 2012-12-13 22:20:18
 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-12-13 22:19:29 | By :
                            creativegu |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ส่วนลบนี่ผมว่าง่ายกว่า 
 ก็แค่รับค่า id ของ ของฟิลด์ที่จะลบมา แล้วก็ action  ตามโค๊ดด้านล่างเลยครับ
 
 Code (PHP)
 
 										  <?
	$objConnect = mysql_connect("localhost","root","xxxxxx") or die("Error Connect to Database");
	$objDB = mysql_select_db("member");
$strSQL = "DELETE FROM admin_table ";
$strSQL .="WHERE id = '".$_GET["id"]."' ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
	header("location:index.php");
}
else
{
	echo "Error Delete [".$strSQL."]";
}
mysql_close($objConnect);
?>
 ใจเย็นๆครับ ตอนผมทำใหม่บางทีงมอยู่สองสามวันกับแค่ลืมใส่ฟันหนู " ตัวเดียว เห่อๆ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-12-13 22:24:06 | By :
                            creativegu |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | คือว่าผมคลิกแก้ไขตรง url  ขึ้น http://localhost/Maefahluang/news_action.php?do=frmedit&id=9  ส่วน 9 ครับเป็นรหัสแต่ตรงข้างล่างโชว์ส่วนที่เราจะแก้ไขครับผมไม่เข้าใจมากเลยตอนนี้ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-12-13 22:41:02 | By :
                            มานะ |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | อ่า แบบนี้หรือเปล่าครับ 
 รับค่ามาตรวจ แล้่วก็แก้ไข แล้วก็ส่งไป action
 
 
 Code (PHP)
 
 <?php
include("../config.inc.php") ;
$strSQL = "SELECT * FROM Maefahluang WHERE id = '".$_GET["id"]."' AND do = '".$_GET["do"]."' ";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$objResult = mysql_fetch_array($objQuery);
if(!$objResult)
{
	echo $_GET[""].""; 
}
  
?>
	<div class="memid" >
	<p align="right">                ชื่อ : <? = $objResult["name"];?><br>
	  รหัส: <? = $objResult["id"];?></p>
	<p align="right"> </p>
	</div>	
	</div>
	<div id="templatemo_right_mid1">
      
<form name="checkForm" action="edit.php" method="post">
 
 <div class="divtable">
	  <table width="452" border="0">
        <tr>
          <td><h1>แก้ไข</h1></td>
        </tr>
      </table>
	  <table width="452" border="0">
        <tr>
          <td><label>
            <div align="center">
              <textarea name="Txt" cols="40" rows="8" id="Txt"><?=nl2br($objResult["detail"]);?>
            </textarea>
            </div>
          </label></td>
        </tr>
      </table>
	  <table width="452"> 
			<tr><td width="137">
			
			   <div class="templatemo_topmenu3">
      <ul>
	  <li>
	    <div align="left"><a href="index.php">ย้อนกลับ</a></div>
	  </li>
	
      </ul>
    </div>
			</td>
			<td width="303">
			
			  <div align="right">
			   <div align="right">
			     <input name="id" type="hidden" class="button_image" id="id" value="<?=$objResult["id"];?>">
				  <input name="do" type="hidden" class="button_image" id="do" value="<?=$objResult["do"];?>">
			     <input type="submit" class="button_image" name="Submit2" value="แก้ไข">
			     
	          </div></td>
			</tr>
	  </table>
 
 </form>
 |  
              | 
 ประวัติการแก้ไข
 2012-12-14 10:23:41
 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-12-14 10:19:07 | By :
                            creativegu |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ขอบคุณคับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-12-14 15:52:04 | By :
                            มานะ |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |