UPDATE ข้อมูลไม่ได้

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา UPDATE ข้อมูลไม่ได้

UPDATE ข้อมูลไม่ได้
หน้าดึงข้อมูล เพื่อจะ update

<?PHP  @session_start();
       include('Connection.php'); ?>

<!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>
<title>.:Reservations Meeting</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css">

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="javascript" src="jquery-1.2.6.min.js"></script>
<script>
function chk_form(){ // เช็คค่าว่าง
	$(":input + span.require").remove();
	$(":input").each(function(){
		$(this).each(function(){	
			if($(this).val()==""){
				$(this).after("<span class=require>*</span>");
			}
		});
	});
	if($(":input").next().is(".require")==false){
		return true;
	}else {
		return false;
	}	
}
</script>

<style type="text/css"> 
.require{
	height:20px;
	color:#FF0000;
	padding-left:5px;
	padding-right:5px;
	font-size:12px;
	line-height:15px;
	width:100px;
	float:none;
}
  </style>

<script language="Javascript">
<!-- ยืนยันการยกเลิก
  function Confirm(object) {
  if (confirm("คุณต้องการยกเลิกใช่หรือไม่?") == true) {
  window.location = 'manage_member.php';
  }
  else {
  return false;
  } }
</script>


</head>

<body>
<table width="973" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><?PHP require('head.php'); ?></td>
  </tr>
  <tr>
    <td><table background="Picture/body.jpg" width="973" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="50">&nbsp;</td>
        <td width="200">&nbsp;</td>
        <td width="723">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td valign="top"><?PHP require('leftmenu.php'); ?></td>
        <td valign="top" align="center"><form id="form2" name="form2" method="post" action="member_updatesave.php">
        
         <?php $sql = "select * from tbl_member where member_id = '$member_id' ";
		$tblmember = mysql_query($sql) or die ("error = $sql");
		$member = mysql_fetch_array($tblmember);  ?>
        
          <table width="600" border="1" cellpadding="5" cellspacing="0">
              <tr>
                <td colspan="2" align="center" bgcolor="#B70404"><strong class="normal2">แก้ไขข้อมูลสมาชิก</strong></td>
                </tr>
              <tr>
                <td align="right" class="normal">รหัสสมาชิก :</td>
                <td><input name="txtmemberid" type="text" id="txtmemberid" value="<?PHP echo $member['member_id']; ?>"/></td>
              </tr>
              <tr>
                <td width="194" align="right" class="normal">ชื่อ :</td>
                <td width="380"><input name="txtfirstname" type="text" id="txtfirstname" value="<?PHP echo $member['firstname']; ?>"/></td>
              </tr>
              <tr>
                <td width="194" align="right" class="normal"><span style="text-align: right">นามสกุล</span>  :</td>
                <td><input name="txtlastname" type="text" id="txtlastname" value="<?PHP echo $member['lastname']; ?>"/></td>
              </tr>
              <tr>
                <td width="194" align="right" class="normal"><span style="text-align: right">แผนก</span>  :</td>
                <td><select name="txtdepartment" id="txtdepartment">
                     <option value="ผู้บริหาร" <?PHP if($member['department_name'] == "ผู้บริหาร") { echo "selected='selected'"; } ?>>ผู้บริหาร</option>
                     <option value="เทคโนโลยีสารสนเทศ" <?PHP if($member['department_name'] == "เทคโนโลยีสารสนเทศ") { echo "selected='selected'"; } ?>>เทคโนโลยีสารสนเทศ</option>
                      <option value="บัญชี" <?PHP if($member['department_name'] == "บัญชี" ) { echo "selected='selected'"; } ?>>บัญชี</option>
                       <option value="บุคคล" <?PHP if($member['department_name'] == "บุคคล") { echo "selected='selected'"; } ?>>บุคคล</option>
                        <option value="การตลาด" <?PHP if($member['department_name'] == "การตลาด") { echo "selected='selected'"; } ?>>การตลาด</option>
                         <option value="งานขาย" <?PHP if($member['department_name'] == "งานขาย") { echo "selected='selected'"; } ?>>งานขาย</option>
                          <option value="ประชาสัมพันธ์" <?PHP if($member['department_name'] == "ประชาสัมพันธ์") { echo "selected='selected'"; } ?>>ประชาสัมพันธ์</option>
                           <option value="วิศวกรรม" <?PHP if($member['department_name'] == "วิศวกรรม") { echo "selected='selected'"; } ?>>วิศวกรรม</option>
                  </select></td>
              </tr>
              <tr>
                <td width="194" align="right" class="normal"><span style="text-align: right">Username</span>  :</td>
                <td><input name="txtusername" type="text" id="txtusername" value="<?PHP echo $member['username']; ?>"/></td>
                </tr>
              <tr>
                <td width="194" align="right" class="normal"><span style="text-align: right">Password</span>  :</td>
                <td><input name="txtpassword" type="password" id="txtpassword" value="<?PHP echo $member['password']; ?>"/></td>
              </tr>
              <tr>
               <td width="194" align="right" class="normal"><span style="text-align: right">Confirm Password</span>  :</td>
                <td><input name="txtconpassword" type="password" id="txtconpassword" value="<?PHP echo $member['password']; ?>"/></td>
              </tr>
              <tr>
                <td width="194" align="right" class="normal"><span style="text-align: right">E-mail</span>  :</td>
                 <td><input name="txtemail" type="text" id="txtemail" value="<?PHP echo $member['email']; ?>"/></td>
              </tr>
              <tr>
               <td width="194" align="right" class="normal">เบอร์โทรศัพท์ :</td>
               <td><input name="txttel" type="text" id="txttel" value="<?php echo $member['tel']; ?>"/></td>
              </tr>
              <tr>
                
              </tr>
            </table>
          <br />
          <table width="200" border="0" align="center">
            <tr>
              <th scope="col"><button type="submit" name="button" id="button" onclick="return chk_form()" value=" "> <img src="picture/Save.png" width="16" height="16" align="center" /> บันทึก</button>
                <input name="member_id" type="hidden" id="member_id" value="<?=$_REQUEST['member_id']?>""/></th>
              <th scope="col"> <button type="reset" name="reset" id="button1"  onclick="return Confirm();" value="cancel"> <img src="picture/Delete.png" width="16" height="16" align="center" /><font color="#000"> ยกเลิก</font></button>
                &nbsp;</th>
            </tr>
          </table>
        </form>
          </td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><?PHP require('footer.php'); ?></td>
  </tr>
</table>
</body>
</html>


Chinjung 158.108.209.xxx 23-10-2014 21:33:35

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
หน้า save ข้อมูล update
<?php   @session_start();
		include('Connection.php');
	    include('function.php');
	

	//เแก้ไขข้อมูลสมาชิก
	$sql = "UPDATE tbl_member SET 
	firstname = '".trim($_POST['txtfirstname'])."' ,
	lastname = '".trim($_POST['txtlastname'])."' ,
	department_name = '".trim($_POST['txtdepartment'])."',
	username = '".trim($_POST['txtusername'])."',
	password = '".trim($_POST['txtpassword'])."',
	email ='".trim($_POST['txtemail'])."',
	tel ='".trim($_POST['txttel'])."'  WHERE member_id = '$member_id'";
	$member = mysql_query($sql);
	
	echo $sql;
	/* exit("<script>alert('แก้ไขข้อมูลสมาชิกเรียบร้อย!');window.location='manage_member.php';
	</script>"); */
	
	
	?>


chinjung 158.108.209.xxx 23-10-2014 21:34
 ความคิดเห็นที่ 2
ในความเห็นที่1 ลองดู บรรทัด ที่14

tel ='".trim($member_id)."'  WHERE member_id = '$member_id'";  


$member_id น่าจะ $_POST['member_id'];


wowowow 110.168.220.xxx 24-10-2014 13:28
 ความคิดเห็นที่ 3
ขอบคุณสำหรับความคิดเห็นที่2ค่ะ แต่ยังงงอยู่ว่านำ  $_POST['member_id']; ใส่แทน $member_id แล้ว ยัง error อยู่ รบกวนช่วยดูอีกทีนะคะว่าผิดตรงไหน  ขอบคุณมากค่ะ
<?php   @session_start();
		include('Connection.php');
	    include('function.php');
	

	//เแก้ไขข้อมูลสมาชิก
	$sql = "UPDATE tbl_member SET 
	firstname = '".trim($_POST['txtfirstname'])."' ,
	lastname = '".trim($_POST['txtlastname'])."' ,
	department_name = '".trim($_POST['txtdepartment'])."',
	username = '".trim($_POST['txtusername'])."',
	password = '".trim($_POST['txtpassword'])."',
	email ='".trim($_POST['txtemail'])."',
	tel ='".trim($_POST['txttel'])."' 

 WHERE member_id = '$_POST['member_id']' ";

	$member = mysql_query($sql);
	
	echo $sql;
	/* exit("<script>alert('แก้ไขข้อมูลสมาชิกเรียบร้อย!');window.location='manage_member.php';
	</script>"); */
	
	
	?>


chinjung 158.108.209.xxx 24-10-2014 19:14
 ความคิดเห็นที่ 4
แก้ได้แล้วค่ะ ขอบคุณมากๆนะคะ คุณ Wowowow


chinjung 158.108.209.xxx 24-10-2014 19:24
 ความคิดเห็นที่ 5
เทคนิคเล็กๆ น้อยๆ ครับ 
ลองใช้ mysql_error();

ถ้าเรามีโค้ดแบบนี้ แล้ว เราพิมอะไรผิดสักอย่าง เช่นใส่ ชื่อ ตารางผิด
ถ้า ชื่อตารางเป็น tbl_member  เราใส่ member

$member_id = 2;
$sql = "select * from member where member_id = '$member_id' ";  
$tblmember = mysql_query($sql) or die ("error = $sql");  



ถ้าหาก error  จะ แสดงข้อความ
error = select * from member where member_id =2
เราต้องมาสักเกตเอาเองว่าผิดตรงไหน


ถ้า เราใช้  mysql_error ();
 
$member_id = 2;
$sql = "select * from member where member_id = '$member_id' ";  
$tblmember = mysql_query($sql) or die (or die(mysql_error()); 
ถ้าหาก error  จะ แสดงข้อความ
Table 'member' doesn't exist

ประมาณนี้ ทำให้เรารู้ ได้ว่าผิดตรงไหน ลองเอาไปใช้ดู


wowowow 110.168.218.xxx 27-10-2014 13:09
 ความคิดเห็นที่ 6
แก้ ก๊อปมาเกิน

    $member_id = 2;  
    $sql = "select * from member where member_id = '$member_id' ";    
    $tblmember = mysql_query($sql) or die (mysql_error());   


wowowow 110.168.218.xxx 27-10-2014 13:11
 ความคิดเห็นที่ 7
นำไปใช้แล้วค่ะ ขอบคุณมากๆนะคะ คุณ Wowowow 


chinjung 158.108.209.xxx 28-10-2014 00:07
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ