A-AA+then

ช่วยดูให้หน่อยครับ ผมทำผิดตรงไหน

2,106

เกิดปัญหาขึ้นอีกแล้วครับตอนแรกทำได้แล้วแต่พอเอามาใช้จริงมันกับเหมือนไม่ทำงานนะครับแล้วก็ไม่ขึ้นerror อีกด้วยผมเลยคิดว่ามันคงไม่ทำงานมากกว่า เลยอยางจะให้ช่วยดูว่าผิดหรือป่าวครับกับการเขียน (ผมเอามาจาก combobox จังหวัด อำเภท ตำบล (UTF))ดูแล้วดูอีกก็ยังไม่เจอครับช่วยดูหน่อยนะครับผม

Code[PHP] editrecordM.php


<?php
session_start();
 include "../config.php";
 include "../auth.inc.php";
 if($_SESSION['ses_Typeuser_Id']=="TU01" or  $_SESSION['ses_Typeuser_Id']=="TU07"){
  if($_SESSION['ses_Typeuser_Id']=="TU07"){
  $ProfileA="ProfileAM.php";
  $addata="addataM.php";
  }else{
  $ProfileA="ProfileA1.php";
  $addata="addata.php";
  }
 }else{
 echo "<script language='javascript'>window.location.href='../index.php';</script>";
 exit();
}
?>

<?php //แสดงข้อมูลที่จะแก้ไข
$Empid=$_REQUEST['Empid']; #ชื่อผู้ใช้ต้องการแก้ไข ที่ส่งมาจาก ProfileA2.php
#$typelink = $_SESSION[ 'typelink'];
 include "CheckYear.php";
# and leaveacc.YearAcc = $DateSqlTS   (SELECT * from leaveacc where YearAcc = $DateSqlTS)

$sql = ("SELECT * from employee
       INNER JOIN leaveacc  ON (employee.Username = leaveacc.Username)
       where Empid=$Empid  and  YearAcc = '$DateSqlTS' ");

$result = mysql_query($sql);
$num_rows = mysql_num_rows($result); 
if ( $num_rows >= 1) {
 $fetcharr = mysql_fetch_array($result);
 $Empid = $fetcharr['Empid'];
 $User_Edit=$fetcharr['Username'];
  $_SESSION['User_Edit']=$User_Edit;
 $Title_Edit = $fetcharr['Title'];
 $Sex_Edit = $fetcharr['Sex'];
 $Fname_Edit = $fetcharr['Fname'];
 $Lname_Edit = $fetcharr['Lname'];
 $Address_Edit = $fetcharr['Address'];
 $Phone_Edit = $fetcharr['Phone'];
 $Date_In =$fetcharr['Date_In'];
 $Typeuser_Edit = $fetcharr['Typeuser_Id'];
 $Typepost_Edit = $fetcharr['Typepost_Id'];
 $Mindept_Edit = $fetcharr['Mindept_Id'];
 $Division_Edit = $fetcharr['Division_Id'];
 $Section_Edit = $fetcharr['Section_Id'];
 $Post_Edit = $fetcharr['Post_Id'];
 $Level_Edit = $fetcharr['Level'];
 $LeaveRight_Edit = $fetcharr['LeaveRight'];
 $LeaveTop_Edit = $fetcharr['LeaveTop'];
 #$YearAcc = $fetcharr['YearAcc'];
 #echo $DateSqlTS;
 #echo $YearAcc;
 #echo $Title_Edit;
   if($Title_Edit=="นาง" ){
   $rechk3="checked";
   $rechkF="checked";
   }elseif($Title_Edit=="นางสาว"){
   $rechk2="checked";
   $rechkF="checked";
   }elseif($Title_Edit=="นาย"){
   $rechk1="checked";
   $rechkM="checked";
   }elseif($Title_Edit !="" and $Sex_Edit=="M" ){
   $rechk4="checked";
   $rechkM="checked";
   }elseif($Title_Edit !="" and $Sex_Edit=="F" ){
   $rechk4="checked";
   $rechkF="checked";
   }
   
   if($Typeuser_Edit=="TU01"){
     $Typeuserselec1 = "checked";
   }elseif($Typeuser_Edit=="TU02"){
     $Typeuserselec2 = "checked";
   }elseif($Typeuser_Edit=="TU03"){
     $Typeuserselec3 = "checked";
   }elseif($Typeuser_Edit=="TU04"){
     $Typeuserselec4 = "checked";
   }elseif($Typeuser_Edit=="TU05"){
     $Typeuserselec5 = "checked";
   }elseif($Typeuser_Edit=="TU06"){
     $Typeuserselec6 = "checked";
   }elseif($Typeuser_Edit=="TU07"){
     $Typeuserselec7 = "checked";
   }elseif($Typeuser_Edit=="TU08"){
     $Typeuserselec8 = "checked";
   }
   
   if($LeaveRight_Edit=="er" or $LeaveRight_Edit==""){
   $LeaveRighter ="selected";
   }elseif($LeaveRight_Edit=="0"){
   $LeaveRight0 ="selected";
   }elseif($LeaveRight_Edit=="10"){
   $LeaveRight10 ="selected";
   }
   
   $MindeptId=$Mindept_Edit;
   $DivisionId=$Division_Edit;
}

if($_POST[Mindept] !="0" && $_POST[Mindept] != "" )
{
 $Mindept_Edit = $_POST[Mindept];
}
elseif($_POST[Division] != "0" && $_POST[Division] != "")
{
 $Division_Edit = $_POST[Division];
}
elseif($_POST[Section] != "0" && $_POST[Section] != "")
{
 $Section_Edit = $_POST[Section];
}elseif($_POST[Post] != "0" && $_POST[Post] != "")
{
 $Post_Edit = $_POST[Post];
}
?>
<!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=windows-874" />
<title><? echo $_SESSION['Titlebar'];?></title>
<script Language="Javascript">
<!--
  function Confup(object) {
  if (confirm("ยืนยันต้องการแก้ไข?
Do u want to update?") == true) {
  return true;
  }
  return false;
  }
 //-->
  </script>

  <script type="text/javascript">
//AJAX
function Inint_AJAX()
{
 try
 {
  return new ActiveXObject( "Msxml2.XMLHTTP" );
 }
 catch ( e )
 {
 };

 try
 {
  return new ActiveXObject( "Microsoft.XMLHTTP" );
 }
 catch ( e )
 {
 };

 try
 {
  return new XMLHttpRequest();
 }
 catch ( e )
 {
 };

 alert( "XMLHttpRequest not supported" );
 return null;
};

function dochange( obj )
{
 var req = Inint_AJAX();
 var Mindept = document.getElementById( 'Mindept' ).value;
 var Division = document.getElementById( 'Division' ).value;
 var Section = document.getElementById( 'Section' ).value;
 var Post = document.getElementById( 'Post' ).value;
 if ( obj && obj.name == 'Mindept' ) //เมื่อทำการเลือที่จังหวัดมา ให้เคลียร์ค่าอำเภอ
 {
  var Division = "";
  var Section = "";
  var Post = "";
 }
 else if ( obj && obj.name == 'Division')
 {
  var Section = "";
  var Post = "";
 }
 else if( obj && obj.name == 'Section')
 {
  var Post = "";
 };
 var data = "Mindept=" + Mindept + "&Division=" + Division + "&Section=" + Section + "&Post=" + Post;
 req.onreadystatechange = function()
 {
  if ( req.readyState == 4 )
  {
   if ( req.status == 200 )
   {
    
    var datas = eval( '(' + req.responseText + ')' ); // JSON
    document.getElementById( 'MindeptDiv' ).innerHTML = datas[0].Mindept;
    document.getElementById( 'DivisionDiv' ).innerHTML = datas[0].Division;
    document.getElementById( 'SectionDiv' ).innerHTML = datas[0].Section;
    document.getElementById( 'PostDiv' ).innerHTML = datas[0].Post;
   };
  };
 };
 req.open( "post" , "pro.php" , true ); //สร้าง connection
 req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" ); // set Header
 req.send( data ); //ส่งค่า
};

//โหลดครั้งแรก
window.onload = function()
{
 dochange( '' );
};
</script>
<style type="text/css">
<!--
body {
 background-image: url();
 background-repeat: repeat-x;
}
.style3 {color: #FF0000; font-weight: bold; }
.style13 {
 font-size: 15px;
 font-weight: bold;
 color: #620001;
}
.style16 {font-size: 14px}
.style17 {font-size: 13px}
.style19 {font-size: 13px; font-weight: bold; }
.style1 {color: #FF0000}
.style20 {color: #620001; font-size: 15px;}
.style7 {color: #620001; font-weight: bold; }
.style9 { color: #0000FF;
 font-style: italic;
}
.style23 {font-size: 13px; color: #FF0000; }
-->

</style>

<script type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
}
//-->

</script>

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body onload="MM_preloadImages('images/IMG/modify2.jpg','images/IMG/del2.jpg','images/IMG/logoff2.jpg','../images/add2.jpg','../images/modify2.jpg','../images/logoff2.jpg','../images/del2.jpg','../images/add_data2.jpg')">
<table width="772" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr><td colspan="5">
  <p align="left"><img src="../images/logoS.jpg" width="780" height="100" /></p>
  </td></tr>

  <td colspan="5" bgcolor="#FFCC33">&nbsp;</td>
</tr>
<tr>
  <td width="111" height="24" background="../images/admin.jpg"><div align="center" class="style3">
    <div align="right" class="style3"></div>
  </div></td>
  <td width="110" bgcolor="#FFFFFF">&nbsp;</td>
  <td width="162">&nbsp;</td>
  <td width="138"> <div align="left"></div></td>
  <td width="270" background="../images/title_del.jpg"><div align="right"></div></td>
</tr>

<tr>
<td align="center" valign="top" bgcolor="#FFCC33">&nbsp;  </td>
  <td bgcolor="#E0E0E0">&nbsp;</td>
  <td colspan="3" bgcolor="#E0E0E0"><span class="style13">แก้ไขขอมูล - ประวัติ</span></td>
  </tr>
<tr>
  <td rowspan="2" align="center" valign="top" bgcolor="#FFCC33">&nbsp;</td>
  <td colspan="4" bgcolor="#E0E0E0"><hr  color="#FF0000"/></td>
</tr>
<tr>
  <td colspan="4" rowspan="2" align="left" valign="top" bgcolor="#E0E0E0"><form name="form1" id="form1" method="post" action="update.php">
    <table width="668" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="111" bgcolor="#E0E0E0"><div align="right" class="style17"></div>
            <div align="right" class="style17">ชื่อผู้ใช้งาน :&nbsp;</div></td>
        <td colspan="2" bgcolor="#E0E0E0"><span class="style17">
          <input name="Username" type="text" id="Username" value="<? echo $User_Edit ?>" maxlength="13" disabled />
&nbsp;&nbsp;</span></td>
        <td colspan="2" bgcolor="#E0E0E0"><span class="style23">* หมายเลขบัตรประชาชน บันทึกแล้วไม่สามารถแก้ไขได้ </span>
            <div align="right"></div>
            <div align="left"></div></td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right"><span class="style17">นาม&nbsp;:&nbsp;</span></div></td>
        <td colspan="4" valign="middle" bgcolor="#E0E0E0"><span class="style17">
          <label>
<input name="Title" type="radio" value="นาย" <? echo "$rechk1";?> />     
นาย</label>
          <label>
          <input name="Title" type="radio" value="นาง" <? echo "$rechk3";?>/>
      นาง</label>
          <label>
          <input name="Title" type="radio" value="นางสาว" <? echo "$rechk2";?>/>
      นางสาว</label>
          <input name="Title" type="radio" value="01" <? echo "$rechk4";?>/>
      อื่นๆ
      <input name="Titleselect" type="text" id="Titleselect" value="<? if($rechk4=="checked"){ echo "$Title_Edit ";}else{ echo"โปรดระบุ"; } ?>" size="10" maxlength="10" />
&nbsp;</span></td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right" class="style17">เลือกเพศ&nbsp;:&nbsp;</div></td>
        <td colspan="4" valign="middle" bgcolor="#E0E0E0"><p class="style17">
            <label> </label>
            <input name="Sex" type="radio" value="M"  <? echo "$rechkM";?>/>
        ชาย
        <input name="Sex" type="radio" value="F" <? echo "$rechkF";?>/>
        หญิง </p></td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right" class="style17">ชื่อ :&nbsp; </div></td>
        <td colspan="2" bgcolor="#E0E0E0"><input name="Fname" type="text" id="Fname" value="<? echo $Fname_Edit ?>" maxlength="40" /></td>
        <td width="261" rowspan="2" align="center" valign="middle" bgcolor="#E0E0E0" class="style23"><strong>&nbsp;&nbsp;</strong>ชื่อ-นามสกุล สามารถบันทึกได้<br />
    &nbsp;&nbsp;ไม่เกิน 40 ตัวอักษร </td>
        <td width="117" bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right" class="style17">นามสกุล&nbsp;:&nbsp;</div></td>
        <td colspan="2" bgcolor="#E0E0E0"><input name="Lname" type="text" id="Lname" value="<? echo $Lname_Edit ?>" maxlength="40" /></td>
        <td bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="5" bgcolor="#E0E0E0"><span class="style17">
          <label> </label>
        </span></td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right" class="style17">ที่อยู่ :&nbsp;</div></td>
        <td colspan="3" rowspan="2" bgcolor="#E0E0E0"><span class="style17"> </span>
            <p class="style17">
              <label>
              <textarea name="Address" cols="40" rows="2" id="Address"><? echo $Address_Edit ?></textarea>
              </label>
          </p></td>
        <td rowspan="2" bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right" class="style17">
            <div align="right"></div>
          </div>
            <div align="right" class="style17">&nbsp;</div></td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right"><span class="style17">โทรศัพท์ :&nbsp;</span></div></td>
        <td colspan="3" bgcolor="#E0E0E0"><span class="style17">
          <input name="Phone" type="text" id="Phone" value="<? echo $Phone_Edit ?>" maxlength="10" />
&nbsp;</span><span class="style23">( ตัวอย่าง 0898825467 )</span></td>
        <td bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right" class="style17">วันที่เริ่มงาน&nbsp;:&nbsp;</div></td>
        <td colspan="3" valign="middle" bgcolor="#E0E0E0"><span class="style17"><? echo date("d",strtotime($Date_In)); echo date("-m-",strtotime($Date_In));echo date("Y",strtotime($Date_In))+543;?><span class="style23">&nbsp;&nbsp;*&nbsp;บันทึกแล้วไม่สามารถแก้ไขได้ </span> </span></td>
        <td bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right" class="style17">สังกัดกรม&nbsp;:&nbsp;</div></td>
        <td colspan="3" bgcolor="#E0E0E0">
          <span class="style17">
          <!-- <select name="Mindept" id="Mindept">
            <option value="er" selected="selected">เลือกกรม</option> -->

            <?
       /* $no=1;
        $resultm=mysql_query("select * from mindept ");
       while($rm=mysql_fetch_array($resultm)) {
        $Mindept_Id=$rm['Mindept_Id'];
        $MindeptN=$rm['Mindept_Name'];
        if($Mindept_Id==$MindeptId){
              $SelectMin="selected";
           $MName=$MindeptN;
        }else{
           $SelectMin="";
        }
        echo "<option value='$Mindept_Id' $SelectMin>$MindeptN</option>";
        $no++;
       } */

       echo '<span id="MindeptDiv">';
       echo "<label for='Mindept'></label>";
       echo "<select name=\"Mindept\" id=\"Mindept\" onchange=\"dochange('Mindept')\">
";
       echo "<option value=\"$Mindept_Edit\">--------------</option> " ;
       echo "</select></span> ";
      ?>
       <!--    </select> -->
          </span></td>
        <td bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right" class="style17">หน่วยงาน&nbsp;:&nbsp;</div></td>
        <td colspan="3" bgcolor="#E0E0E0">
         <!--  <select name="Division" id="Division">
            <option value="er" selected="selected">เลือกหน่วยงาน</option> -->

            <?
       /* $no=1;
        $resultd=mysql_query("select * from Division");
       while($rd=mysql_fetch_array($resultd)) {
        $Division_Id=$rd['Division_Id'];
        $DivisionN=$rd['Division_Name'];
        if($Division_Id==$DivisionId){
              $SelectDiv="selected";
           $DName=$DivisionN;
        }else{
           $SelectDiv="";
        }
        echo "<option value='$Division_Id' $SelectDiv>$DivisionN</option>";
        $no++;
       } */

       echo '<span id="DivisionDiv">';
       echo "<label for='Division'></label>";
       echo "<select name=\"Division\" id=\"Division\" onchange=\"dochange('Division')\"> ";
       echo "<option value=\"$Division_Edit\">--------------</option> " ;
       echo "</select></span> ";
      ?>

          <!-- </select> -->        </td>
        <td bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right" class="style17">ฝ่าย&nbsp;:&nbsp;</div></td>
        <td colspan="3" bgcolor="#E0E0E0">
          <!-- <select name="Section" id="Section">
            <option value="er" selected="selected">เลือกฝ่าย</option> -->

            <?
       /* $no=1;
       include "../config.php";
       $sqls="select * from Section where Division_Id='$Division_Edit' ";
       $results=mysql_db_query($dbname,$sqls);
       while($rs=mysql_fetch_array($results)) {
        $SectionId=$rs[Section_Id];
        $SectionName=$rs[Section_Name];
        if($SectionId==$Section_Edit){
              $SelectSec="selected";
        }elseif($SectionId!=$Section_Edit){
           $SelectSec="";
        }
        echo "<option value='$SectionId' $SelectSec>$SectionName</option>";
        $no++;
       }
       mysql_close(); */

       echo '<span id="SectionDiv">';
       echo "<label for='Section'></label>";
       echo "<select name=\"Section\" id=\"Section\" onchange=\"dochange('Section')\"> ";
       echo "<option value=\"$Section_Edit\">--------------</option> " ;
       echo "</select></span> ";
      ?>

         <!--  </select> -->
        </td>
        <td bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right" class="style17">ตำแหน่ง&nbsp;:&nbsp;</div></td>
        <td colspan="3" bgcolor="#E0E0E0">
         <!--  <select name="Post" id="Post">
            <option value="er" selected="selected">เลือกตำแหน่ง</option> -->

            <?
      /* $no=1;
      include "../config.php";
      $sqlp="select * from post
             INNER JOIN section ON (post.Section_Id = section.Section_Id )
              INNER JOIN division ON (division.Division_Id = section.Division_Id )
       where division.Division_Id='$Division_Edit' and section.Division_Id = '$Division_Edit' and post.Section_Id = section.Section_Id ";
      $resultp=mysql_db_query($dbname,$sqlp);
      while($rp=mysql_fetch_array($resultp)) {
       $PostId=$rp[Post_Id];
       $PostName=$rp[Post_Name];
        if($PostId==$Post_Edit){
              $SelectPost="selected";
        }elseif($PostId!=$Post_Edit){
           $SelectPost="";
        }
       echo "<option value='$PostId' $SelectPost>$PostName</option>";
       $no++;
      }
      mysql_close(); */

      echo '<span id="PostDiv">';
      echo "<label for='Post'></label>";
      echo "<select name=\"Post\" id=\"Post\"> ";//รายการสุดท้ายไม่ต้องมี event แล้ว
      echo "<option value=\"$Post_Edit\">--------------</option>
" ;
      echo "</select></span> ";
     ?>

        <!--   </select> -->
        </td>
        <td bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right" class="style17">ระดับ&nbsp;:&nbsp;</div></td>
        <td colspan="3" bgcolor="#E0E0E0">
          <input name="Level" type="text" id="Level" value="<? if($Level_Edit!="")echo "$Level_Edit";else echo"0"; ?>" size="6" maxlength="10" /></td>
        <td bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top" bgcolor="#E0E0E0"><div align="right"><span class="style17">ประเภทผู้ใช้&nbsp;:&nbsp;</span></div></td>
        <td valign="top" bgcolor="#E0E0E0"><label> </label>
            <span class="style17">
            <label>
            <input type="radio" name="Typeuser" value="TU07" <? echo "$Typeuserselec7";?> />
            ผู้ดูแลระบบ(ระดับกรม)<br />
            <input type="radio" name="Typeuser" value="TU01" <? echo "$Typeuserselec1";?> />
            ผู้ดูแลระบบ(ระดับกอง)<br />
            <input type="radio" name="Typeuser" value="TU02" <? echo "$Typeuserselec2";?> />
            ผู้บริหาร<br />
            <input type="radio" name="Typeuser" value="TU08" <? echo "$Typeuserselec8";?> />
            รองผู้บริหารและ หัวหน้างาน<br />
            </label>
          </span> </td>
        <td colspan="2" valign="top" bgcolor="#E0E0E0"><label> </label>
            <span class="style17">
            <label>
            <input type="radio" name="Typeuser" value="TU03" <? echo "$Typeuserselec3";?> />
            หัวหน้างาน <br />
            <input type="radio" name="Typeuser" value="TU06" <? echo "$Typeuserselec6";?> />
            หัวหน้างานและ ผู้ตรวจสอบ <br />
            <input type="radio" name="Typeuser" value="TU05" <? echo "$Typeuserselec5";?> />
            ผู้ตรวจสอบ <br />
            <input type="radio" name="Typeuser" value="TU04" <? echo "$Typeuserselec4";?> />
            พนักงาน<br />
            </label>
          </span> </td>
        <td bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right"><span class="style17">ประเภทพนักงาน&nbsp;:&nbsp;</span></div></td>
        <td colspan="3" bgcolor="#E0E0E0">
          <select name="Typepost" id="Typepost">
            <option value="er" selected="selected">เลือกประเภท</option>
            <?
        $no=1;
        include "../config.php";
        $sql="select * from Typepost";
        $result=mysql_db_query($dbname,$sql);
        while($r=mysql_fetch_array($result)) {
        $Typepost_Id=$r[Typepost_Id];
        $Typepost_Name=$r[Typepost_Name];
          if($Typepost_Id==$Typepost_Edit){
             $SelectTp="selected";
          }elseif($Typepost_Id!=$Typepost_Edit){
             $SelectTp="";
          }
        echo "<option value='$Typepost_Id' $SelectTp>$Typepost_Name</option>";
        $no++;
       }
       mysql_close();
      ?>

          </select>
        </td>
        <td bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right"><span class="style17">วันลาพักผ่อน&nbsp;:&nbsp;</span></div></td>
        <td width="178" bgcolor="#E0E0E0"><select name="LeaveRight" id="LeaveRight">
            <option value="er" <? echo "$LeaveRighter";?> >เลือก</option>
            <option value="0"  <? echo "$LeaveRight0";?> >0</option>
            <option value="10" <? echo "$LeaveRight10";?> >10</option>
        </select></td>
        <td colspan="2" bgcolor="#E0E0E0">&nbsp;<span class="style23">มีสิทธิลาพักผ่อนประจำปีนี้</span></td>
        <td bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td bgcolor="#E0E0E0"><div align="right"><span class="style17">ยอดวันลา&nbsp;:</span>&nbsp;</div></td>
        <td bgcolor="#E0E0E0"><input name="LeaveTop" type="text" id="LeaveTop" value="<? if(isset($LeaveTop_Edit))echo "$LeaveTop_Edit";else echo"0"; ?>" size="8" maxlength="2" /></td>
        <td colspan="3" bgcolor="#E0E0E0"> &nbsp;<span class="style23">ยอดวันลาจากปีงบประมาณที่แล้ว(ใช้ตอนเริ่มระบบเท่านั้น)</span></td>
      </tr>
      <tr>
        <td colspan="5" bgcolor="#E0E0E0">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="5" bgcolor="#E0E0E0"><div align="center">
            <input type="submit" name="Submit" value="บันทึกข้อมูล" />
        </div></td>
      </tr>
      <tr>
        <td colspan="5"></td>
      </tr>
    </table>
  </form></td>
</tr>
<tr bgcolor="#FFCC33">
  <td align="center" valign="top"><table border="0" align="left" cellpadding="0" cellspacing="0">
    <tr>
      <td align="left" valign="top"><a href="<? echo "$ProfileA"; ?>" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('add','','../images/add2.jpg',1)"><img src="../images/add1.jpg" name="add" width="110" height="24" border="0" id="add" /></a></td>
    </tr>
    <tr>
      <td align="left" valign="top"><a href="ProfileA2.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('modify','','../images/modify2.jpg',1)"><img src="../images/modify.jpg" name="modify" width="110" height="24" border="0" id="modify" /></a></td>
    </tr>
    <tr>
      <td align="left" valign="top"><a href="ProfileA3.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image5','','../images/del2.jpg',1)"><img src="../images/del.jpg" name="Image5" width="110" height="24" border="0" id="Image5" /></a></td>
    </tr>
    <tr>
      <td align="left" valign="top"><a href="<? echo "$addata"; ?>" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('adddata','','../images/add_data2.jpg',1)"><img src="../images/add_data.jpg" name="adddata" width="110" height="24" border="0" id="adddata" /></a></td>
    </tr>
    <tr>
      <td align="left" valign="top">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="top"><a href="../logoff.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('logoff','','../images/logoff2.jpg',1)"><img src="../images/logoff.jpg" name="logoff" width="110" height="24" border="0" id="logoff" /></a><a href="../logoff.php"></a></td>
    </tr>
  </table></td>
  </tr>
<tr>
  <td bgcolor="#FFCC33">&nbsp;</td>
  <td colspan="4" bgcolor="#E0E0E0"><hr color="#FF0000"/></td>
  </tr>
<tr>
  <td bgcolor="#FFCC33">&nbsp;</td>
  <td colspan="4">&nbsp;</td>
  </tr>
<tr>
  <td background="../images/adminL.jpg">&nbsp;</td>
  <td colspan="2" bgcolor="#FFCC33">&nbsp;</td>
  <td colspan="2" bgcolor="#FFCC33">&nbsp;</td>
</tr>
<tr>
  <td height="56" colspan="5"><div align="center">
    <table width="781" height="55" border="0" cellspacing="0">
      <tr>
        <td background="../images/buttom.jpg"> <div align="center" class="style16">กรมวิทยาศาสตร์การแพทย์ กระทรวงสาธารณสุข 88/7 ถ.ติวานนท์ อ.เมือง จ.นนทบุรี 11000. <br />
  โทรศัพท์ (02) 589-0022, 951-0000 </div></td>
      </tr>
    </table>
    </div></td>
</tr>
</table>
</body>
</html>


อีกไฟล์ที่ใช้ในการทำงาน

Code[php]
pro.php

<?
 header( "Expires: Sat, 1 Jan 2005 00:00:00 GMT" );
 header( "Last-Modified: ".gmdate( "D, d M Y H:i:s" )."GMT" );
 header( "Cache-Control: no-cache, must-revalidate" );
 header( "Pragma: no-cache" );
 header( "content-type: application/x-javascript; charset=UTF-8" );


 $Mindept_Edit = $_POST[Mindept];
 $Division_Edit = $_POST[Division];
 $Section_Edit = $_POST[Section];
 $Post_Edit = $_POST[Post];

 $hostname_conn = "localhost";
 $username_conn = "root";
 $password_conn = "root";
 $database_conn = "officedb";
 mysql_connect( $hostname_conn , $username_conn , $password_conn ) or die( "เชื่อมต่อฐานข้อมูลไม่ได้" );
 mysql_select_db( $database_conn ) or die( "เลือกฐานข้อมูลไม่ได้" );// เลือกฐานข้อมูล
 mysql_query('SET CHARACTER SET utf8');
 mysql_query('SET NAMES utf8');

 //ให้คืนค่าจังหวัดไว้เป็นอันดับแรก
 $sql = "SELECT Mindept_id,Mindept_Name FROM mindept";
 $result = mysql_query( $sql );
 echo "[{\"Mindept\":\"";
 echo "<label for='Mindept'></label>";
 echo "<select name='Mindept' id='Mindept' onchange='dochange(this)'>";
 echo "<option value='0'>--กรุณาเลือกจังหวัด--</option>";
 while( $fetcharr = mysql_fetch_array( $result ) )
 {
  $id_Mindept = $fetcharr[Mindept_id];
  $name_Mindept = $fetcharr[Mindept_Name];
  echo "<option value='$id_Mindept'";
  if ( $Mindept_Edit == $id_Mindept ) //เลือกจังหวัดที่เลือกไว้
  {
   echo " selected='selected'";
  };
  echo ">
$name_Mindept</option>";
 };
 echo "</select>\",\"Division\":\"";

 echo "<label for='Division'></label>";
 echo "<select name='Division' id='Division' onchange='dochange(this)'>";
 //ถ้ามีการเลือกจังหวัดมาแล้วให้แสดงอำเภอต่อ
 if ( $Mindept_Edit != "0" && $Mindept_Edit != "" )
 {
  echo "<option value='0'>--กรุณาเลือกอำเภอ--</option>";
  $sql = "SELECT Division_Id,Division_Name FROM division WHERE Mindept_Id='$Mindept_Edit'";
  $result = mysql_query( $sql );
  while( $fetcharr = mysql_fetch_array( $result ) )
  {
   $id_Divistion = $fetcharr[Division_Id];
   $name_Divistion = $fetcharr[Division_Name];
   echo "<option value='$id_Divistion'";
   if ( $Division_Edit == $id_Divistion ) //เลือกอำเภอที่เลือกไว้
   {
    echo " selected='selected'";
   };
   echo ">
$name_Divistion</option>";
  };
 }
 else
 {
  echo "<option value=''>--------------</option>";
 };

 echo "</select>\",\"Section\":\"";

 echo "<label for='Section'></label>";
 echo "<select name='Section' id='Section' onchange='dochange(this)'>";

 //ถ้ามีการเลือกอำเภอมาแล้วให้แสดงตำบลต่อ
 if ( $Division_Edit != "0" && $Division_Edit != "" )
 {
  echo "<option value='0'>--กรุณาเลือกตำบล--</option>";
  $sql = "SELECT Section_Id,Section_Name FROM section WHERE Division_Id=$Division_Edit";
  $result = mysql_query( $sql );
  while( $fetcharr = mysql_fetch_array( $result ) )
  {
   $id_Section = $fetcharr[Section_Id];
   $name_Section = $fetcharr[Section_Name];
   echo "<option value='$id_Section'";
   if ( $Section_Edit == $id_Section ) //เลือกตำบลที่เลือกไว้
   {
    echo " selected='selected'";
  

5 ความคิดเห็น

รบกวนช่วยบอกรายละเอียดของ เอ๋อเร๋อ ด้วยคร้บ
จะได้เป็นข้อมูลใหช่วยหาจุดที่คาดว่าจะผิดพลาดได้ง่ายขึ้น
ยกโค้ดให้มาดูเต็มๆ แบบนี้แล้วมึนครับ ตาลายไปหมดแล้ว

1

คือส่วนของ Ajax ไม่ทำงานนะครับ การที่นะเรียกไฟล์pro.phpมาใช้งานมันไม่ขึ้นมานะครับ

2

3

 ระบุอีกนิดคงจะดี
4

จะตรวจ pro.php ก็ไม่ยากนี่ครับ ให้ alert(req.responseText) ดูตอนที่รับค่าจาก AJAX ก็จะรู้ว่า pro.php ส่งอะไรกลับมา แล้วก็ไปแก้ให้มันถูกต้อง

วิธีที่ง่ายกว่าคือทดสอบโค้ดบน firefox ที่ติดตั้ง firebug จะสามารถดูได้ทั้งค่าที่ส่งไปและรับกลับ โดยที่ไม่ต้องดัดแปลงโค้ดเลย
5
^