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

HOME > PHP > PHP Forum > สืบเนื่องจาก PHP MySQL Add/Insert/Edit/Delete to MySQL On Same Form



 

สืบเนื่องจาก PHP MySQL Add/Insert/Edit/Delete to MySQL On Same Form

 



Topic : 085649



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



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




คือไม่สามารถ edit ได้ค่ะ คือถ้าในตัวอย่าง

บรรทัดที่ 063 --> $strSQL = "SELECT * FROM customer"; ถ้าอย่างงี้แล้วไม่มีปัญหา แต่ถ้า select แบบมีเงื่อนไข where ด้วย อาจจะรับค่ามาจากอีกหน้านึงมาก่อนหน่ะค่ะ
เช่น $strSQL = "SELECT * FROM customer where ipp = '$ipp_req' and pw = '$pw_req' ";
ข้อมูลที่ลิสต์มาก็จะมาตามเงื่อนไขที่เราสั่งไป ก็จะมีปุ่ม edit กับ delete อยู่ข้างหลังต่อท้าย เหมือนในตัวอย่าง
แล้วเวลากด edit แล้วทุกอย่างหายหมดเลย ไม่มีอะไรเลยค่ะ เหมือนว่าต้องส่งค่าอะไรมาด้วยรึปล่าวค๊ะ ลองพยายามแล้ว มันก็ยังไม่ได้อ่ะค่ะ ช่วยชี้แนะด้วยค่ะ



Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-10-19 11:40:46 By : keewa View : 1329 Reply : 3
 

 

No. 1



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



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


โอ๊ะ โอะ ทำได้แล้วค่ะ ต้องแทนค่าตัวแปรส่งไปด้วย แต่ส่งผิดตัว ผิดที่ มันเลยไม่ออก






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-10-19 14:17:12 By : keewa
 


 

No. 2



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

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

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


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-10-20 08:21:24 By : mr.win
 

 

No. 3

Guest


Code (PHP)
<?php session_start();

      include("../config/config_db.php");
	 
      $login = $_SESSION['login'];
	  $conn  = mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error());
      $db    = mysql_select_db($dbname) or die(mysql_error());
	  mysql_query("SET NAMES UTF8");
	  $sql	 = "select * from tbank_admin where office_id = '$login'";
	  $query = mysql_query($sql) or die(mysql_error());
	  $row   = mysql_fetch_array($query); 

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Appointment</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 12px;
}
a:link {
	color: #36F;
}
a:visited {
	color: #36F;
}
a:hover {
	color: #36F;
}
a:active {
	color: #36F;
}
.font_comment {
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 12px;
	color: #F00;
}
-->
body, th, td, input, textarea, select {
	line-height: 16px;
	font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
	font-size: 13px;
	color: #3F3F3F;
}
</style>

    <!-- link calendar files  -->
	<script language="JavaScript" src="calendar_eu.js"></script>
	<link rel="stylesheet" href="calendar.css">

</head>
<body>
<?

//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update"){
	$strSQL = "UPDATE tbank_domicile_marketing SET ";
	$strSQL .="office_id        = '".$_POST["txtEditOfficeID"]."' ";
	$strSQL .=",password        = '".$_POST["txtEditPassword"]."' ";
	$strSQL .=",ao_full_name    = '".$_POST["txtEditAoFullName"]."' ";
	$strSQL .=",ao_eng_name     = '".$_POST["txtEditAoEngName"]."' ";
	$strSQL .=",branch_code     = '".$_POST["txtEditBranchCode"]."' ";
	$strSQL .=",branch_name     = '".$_POST["txtEditBranchName"]."' ";
	$strSQL .=",position        = '".$_POST["txtEditPosition"]."' ";
	$strSQL .=",level           = '".$_POST["txtEditLevel"]."' ";
	$strSQL .=",limit_value     = '".$_POST["txtEditLimitValue"]."' ";
	$strSQL .=",current_status  = '".$_POST["txtEditCurrentStatus"]."' ";
	$strSQL .="WHERE office_id = '".$_POST["hdnEditOfficeID"]."' ";
	$objQuery = mysql_query($strSQL);
	if(!$objQuery){
		echo "Error Update [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}

//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
	$strSQL = "DELETE FROM tbank_domicile_marketing ";
	$strSQL .="WHERE office_id = '".$_GET["office_id"]."' ";
	$objQuery = mysql_query($strSQL);
	if(!$objQuery){
		echo "Error Delete [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}


if($_GET["txtKeyword"] != ""){
          $strSQL = "SELECT * FROM tbank_domicile_marketing
                     WHERE office_id LIKE '%".$_GET["txtKeyword"]."%'
					 OR password LIKE '%".$_GET["txtKeyword"]."%'
	                 OR ao_full_name LIKE '%".$_GET["txtKeyword"]."%'
	                 OR ao_eng_name  LIKE '%".$_GET["txtKeyword"]."%'
	                 OR branch_code  LIKE '%".$_GET["txtKeyword"]."%'
	                 OR branch_name  LIKE '%".$_GET["txtKeyword"]."%'
	                 OR position     LIKE '%".$_GET["txtKeyword"]."%'
	                 OR level        LIKE '%".$_GET["txtKeyword"]."%'
	                 OR limit_value  LIKE '%".$_GET["txtKeyword"]."%'
	                 OR current_status LIKE '%".$_GET["txtKeyword"]."%'  ";
}else{
          $strSQL = "SELECT * FROM tbank_domicile_marketing ";
}
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
?>
 
<form name="frmMain" method="post" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<input type="hidden" name="hdnCmd" value="">
  <table width="916" border="0" align="center" cellpadding="2" cellspacing="2">
    <tr>
      <td colspan="4"><img src="../images/manage_report.jpg" alt="" width="916" height="64" border="0" usemap="#Map" /></td>
    </tr>
    <tr>
      <td colspan="4">&nbsp;</td>
    </tr>
    <tr>
      <td width="474">You are here : <a href="admin_login.php">Admin_Login</a>/<a href="#">Upload Report</a></td>
      <td width="352" align="right"><?php 
	            echo "Username :  ". $row['office_id']." ";
	            echo " ".$row['admin_full_name']." "; 
                $_SESSION['login']              =   $login; 
			    $office_id	                    =   $row['office_id'];
				$admin_full_name	            =   $row['admin_full_name'];
				$_SESSION['office_id']          =   $office_id;
				$_SESSION['admin_full_name']	=   $admin_full_name;
				                       
				
		    ?>
        </td>
      <td colspan="2" align="right"><a href="../logout.php"><img src="../images/pic_logout.jpg" alt="" width="77" height="23" border="0" /></a></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td colspan="2" align="right">&nbsp;</td>
    </tr>
    <tr>
    </tr>
    <tr>
      <td colspan="4" align="center">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="4" align="center">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="4">
      <input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_GET["txtKeyword"];?>" />
      <input type="submit" value="Search" /></td>
    </tr>
    <tr>
      <td colspan="4">
      
  <?php
     // Logic ในการแบ่งหน้าจอ
	$Per_Page = 30;   // ตั้งค่าว่า 1 หน้าให้มีกี่รายการ
	$Page = $_GET["Page"];
	if(!$_GET["Page"])
	{
		$Page=1;
	}

	$Prev_Page = $Page-1;
	$Next_Page = $Page+1;

	$Page_Start = (($Per_Page*$Page)-$Per_Page);
	if($Num_Rows<=$Per_Page)
	{
		$Num_Pages =1;
	}
	else if(($Num_Rows % $Per_Page)==0)
	{
		$Num_Pages =($Num_Rows/$Per_Page) ;
	}
	else
	{
		$Num_Pages =($Num_Rows/$Per_Page)+1;
		$Num_Pages = (int)$Num_Pages;
	}


	$strSort = $_GET["sort"];
    if($strSort == "")
    {
	//column to order	
	$strSort = "office_id";
	$strSort = "ao_full_name";
	$strSort = 'ao_eng_name';
	$strSort = 'branch_code';
	$strSort = 'branch_name';
	$strSort = 'position';
	$strSort = 'level';
	$strSort = 'limit_value';
	$strSort = 'current_status';
	
    }

    $strOrder = $_GET["order"];
    if($strOrder == "")
    {
	$strOrder = "DESC";
    }

$strSQL .=" ORDER BY ".$strSort." ".$strOrder." LIMIT $Page_Start , $Per_Page";
$objQuery  = mysql_query($strSQL);

$strNewOrder = $strOrder == 'DESC' ? 'ASC' : 'DESC';

?>
<table width="100%" border="0" align="center">
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <th width="50" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=office_id&order=<?=$strNewOrder?>">OFFICE ID</a></div></th>
    <th width="50" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=password&order=<?=$strNewOrder?>">PASSWORD</a></div></th>
    <th width="120" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=ao_full_name&order=<?=$strNewOrder?>">THAI NAME</a></div></th>
    <th width="80" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=ao_eng_name&order=<?=$strNewOrder?>">ENG NAME</a></div></th>
     <th width="50" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=branch_code&order=<?=$strNewOrder?>">BRANCH CODE</a></div></th>
    <th width="80" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=branch_name&order=<?=$strNewOrder?>">BRANCH NAME</a></div></th>
    <th width="50" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=position&order=<?=$strNewOrder?>">POSITION</a></div></th>
    <th width="25" align="left" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=level&order=<?=$strNewOrder?>">LEVEL</a></div></th>
     <th width="25" align="left" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=current_status&order=<?=$strNewOrder?>">STATUS</a></div></th>
    <th width="40" bgcolor="#F77306"> <div align="center">EDIT</div></th>
    <th width="40" bgcolor="#F77306"> <div align="center">DELETE</div></th>
  </tr>
<?php

	//โชว์ข้อมูลและสลับสีแถว
	
    $i=0;
	while($objResult = mysql_fetch_array($objQuery)){
	$i++;
		if($i%2==0){
		$bg = "#CCCCCC";
		}else{
		$bg = "#EEEDE9";
		}
		
    if($objResult["office_id"] == $_GET["office_id"] and $_GET["Action"] == "Edit"){
?>
   <tr>
    <td bgcolor="<?=$bg?>"><div align="center">
		<input name="txtEditOfficeID" type="text" readonly="readonly" value="<?=$objResult["office_id"];?>" size="8" >
		<input type="hidden" name="hdnEditOfficeID" size="5" value="<?=$objResult["office_id"];?>"></div></td>
    <td bgcolor="<?=$bg?>"><input type="text" name="txtEditPassword" size="10" value="<?=$objResult["password"];?>"></td>
    <td bgcolor="<?=$bg?>"><input type="text" name="txtEditAoFullName" size="20" value="<?=$objResult["ao_full_name"];?>"></td>
    <td align="left" bgcolor="<?=$bg?>"><input name="txtEditAoEngName" type="text"  
    value="<?=$objResult["ao_eng_name"];?>" size="15"></td>
    <td bgcolor="<?=$bg?>"><input type="text" name="txtEditBranchCode" size="5" value="<?=$objResult["branch_code"];?>"></td>
    <td bgcolor="<?=$bg?>"><input type="text" name="txtEditBranchName" size="15" value="<?=$objResult["branch_name"];?>"></td>
    <td align="left" bgcolor="<?=$bg?>"><input name="txtEditPosition" type="text"  
    value="<?=$objResult["position"];?>" size="15"></td>
    <td align="left" bgcolor="<?=$bg?>"><input name="txtEditLevel" type="text"  
    value="<?=$objResult["level"];?>" size="2"></td>
     <td align="left" bgcolor="<?=$bg?>"><input name="txtEditCurrentStatus" type="text"  
    value="<?=$objResult["current_status"];?>" size="2"></td>
    <td colspan="2" align="right" bgcolor="<?=$bg?>"><div align="center">
      <input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
	  <input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';">
    </div></td>
  </tr>
  <?
	}else{
  ?>
  <tr>
    <td bgcolor="<?=$bg?>"><div align="left"><?=$objResult["office_id"];?></div></td>
    <td bgcolor="<?=$bg?>" align="left"><?=$objResult["password"];?></td>
    <td bgcolor="<?=$bg?>" align="left"><?=$objResult["ao_full_name"];?></td>
    <td align="left" bgcolor="<?=$bg?>"><div align="left"><?=$objResult["ao_eng_name"];?></div></td>
    <td bgcolor="<?=$bg?>" align="center"><?=$objResult["branch_code"];?></td>
    <td bgcolor="<?=$bg?>" align="left"><?=$objResult["branch_name"];?></td>
    <td align="left" bgcolor="<?=$bg?>"><div align="left"><?=$objResult["position"];?></div></td>
    <td align="left" bgcolor="<?=$bg?>"><div align="center"><?=$objResult["level"];?></div></td>
    <td align="left" bgcolor="<?=$bg?>"><div align="center"><?=$objResult["current_status"];?></div></td>
    <td align="center" bgcolor="<?=$bg?>"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&office_id=<?=$objResult["office_id"];?>">Edit</a></td>
	<td align="center" bgcolor="<?=$bg?>"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&office_id=<?=$objResult["office_id"];?>';}">Delete</a></td>
  </tr>
  <?php } ?>
<?php } ?>
</table>
      </td>
    </tr>
    <tr>
      <td colspan="4" align="center">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="4" align="center"><strong>Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page : </strong>
    <?
	if($Prev_Page)
	{
		echo " <a href='$_SERVER[PHP_SELF]?Page=$Prev_Page&sort=$strSort&txtKeyword=$_GET[txtKeyword]'><< Back</a> ";
	}

	for($i=1; $i<=$Num_Pages; $i++){
		if($i != $Page)
		{
		echo "[ <a href='$_SERVER[PHP_SELF]?Page=$i&sort=$strSort&txtKeyword=$_GET[txtKeyword]'>$i</a> ]";
		}
		else
		{
		echo "<b> $i </b>";
		}
	}
	if($Page!=$Num_Pages)
	{
		echo " <a href ='$_SERVER[PHP_SELF]?Page=$Next_Page&sort=$strSort&txtKeyword=$_GET[txtKeyword]'>Next>></a> ";
	}	
	
	mysql_close($conn); 
	?>
      
      </td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
<map name="Map" id="Map">
  <area shape="rect" coords="110,44,196,67" href="change_ao_owner.php" />
</map>
</body>
</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-10-22 19:19:18 By : Christopher
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สืบเนื่องจาก PHP MySQL Add/Insert/Edit/Delete to MySQL On Same Form
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 04
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 อัตราราคา คลิกที่นี่