2015-05-14 39 views
0

我有一個帶編輯按鈕的顯示文件,當用戶點擊編輯按鈕時,一個窗口應該彈出來自數據庫的數據。如何在php中顯示從jquery對話框彈出的mysql數據庫中選擇的記錄?

我想在我的應用程序中做上述書面功能。

所以請幫助我。

這是我的代碼如下。

編輯按鈕代碼。

<a id="edit_docid" href="edit_doctor.php?id=<?php echo $tmpdocId;?>" data-target="#edit_doctor" >Edit</a> 

編輯功能代碼。

<div id="edit_doctor" > 

<?php 
include("db.php"); 

    $tmpId = $_REQUEST["DocID"]; 

    $result = mysql_query("select * from doctor 
    where doctor_id = '$tmpId'") or die(mysql_error()); 

    $row = mysql_fetch_array($result); 
    if (!$result) 
    { 
     die("Error: Data not found.."); 
    } 

    $doctor_name = $row['doctor_name']; 
    $doctor_email = $row['doctor_email']; 
    $user_name = $row['username']; 
    $doctor_password = $row['doctor_password']; 
    $doctor_address = $row['doctor_address']; 
    $doctor_phone = $row['doctor_phone']; 
    $doctor_dept_name = $row['doctor_dept_name']; 


    if(isset($_POST['update'])) 
    { 

    $edit_doctor_name = $_POST["edit_doctor_name"]; 
    $edit_doctor_email = $_POST["edit_doctor_email"]; 
    $edit_user_name = $_POST["edit_user_name"]; 
    $edit_doctor_password = $_POST["edit_doctor_password"]; 
    $edit_doctor_address = mysql_real_escape_string($_POST['edit_doctor_address']); 
    $edit_doctor_phone = $_POST["edit_doctor_phone"]; 
    $edit_doctor_dept_name = $_POST["edit_doctor_dept_name"]; 


    $query=mysql_query("UPDATE doctor 
         SET doctor_name = '$edit_doctor_name', 
         doctor_email = '$edit_doctor_email', 
         username='$edit_user_name', 
         doctor_password = '$edit_doctor_password', 
         doctor_address = '$edit_doctor_address', 
         doctor_phone = '$edit_doctor_phone', 
         doctor_dept_name = '$edit_doctor_dept_name' 
         WHERE doctor_id = '$tmpId'") 
         or die(mysql_error()); 

    echo "<script>alert('Record Updated sucessfully...!!!!')</script>"; 

    echo "<meta http-equiv='refresh' content='0;url=disdoctor.php'>";  
    } 

mysql_close($con); 

?> 
<div class="box"> 

    <form id="form" name="registration" method="post" > 

    <table class="addtable_cls"style="margin-top:2%;margin-left: 16px;"cellspacing="1" cellpadding="10"> 
     <tr><td style="text-align:left" ><label for="name">Name<font color="red">*</font> </label></td> 
     <td ><input type="text" id="doctorName" name="edit_doctor_name" placeholder=" Name" onblur="allLetter(document.registration.fname)" required value="<?php echo $row['doctor_name']; ?>"/> 
     </td><td><img src="images2/image.png" class="masterTooltip" title="eg. Last First Middle name"></td><td style="text-align:left"><i name="nameb"style='color:red' id='unm' ></i></td></tr> 

     <tr><td style="text-align:left"> <label for="email" >Email</label></td> 
     <td ><input type="text" id="doctorEmail" name="edit_doctor_email" onblur="myfun()" placeholder="Email" required value="<?php echo $row['doctor_email']; ?>"/> 
     </td><td><img src="images2/image.png" class="masterTooltip" title="Enter valid email for eg. [email protected]"></td><td style="text-align:left"><i style='color:red' id='email' ></i></td></tr> 

     <tr ><td style="text-align:left"> <label for="uname" >User Name<font color="red">*</font></label></td> 
<td ><input type="text" id="userName" name="edit_user_name" onblur="allLetter1(document.registration.edit_user_name)" placeholder="User Name" required value="<?php echo $user_name; ?>"/> 
</td><td><img src="images2/image.png" class="masterTooltip" title="UserName contains a-z, A-Z, 0-9, _"></td><td style="text-align:left"><i name="nameb"style='color:red' id='usernm' ></i></td></tr> 


     <tr><td style="text-align:left"> <label for="password" >Password <font color="red">*</font></label></td> 
     <td ><input type="password" id="doctorPassword" name="edit_doctor_password" placeholder=" Password" onblur="passid_validation(7,20)" value="<?php echo $row['doctor_password']; ?>"/> 
     </td><td></td><td style="text-align:left"><i style='color:red' id='pass' ></i></td></tr> 


     <tr><td></td><td ><input id="sub" type="submit" name="update" value="Update Doctor" onclick="return validateDoctor()"/></td></tr> 
    </table> 
</form> 
</div> 
</div> 
+0

您可以使用Ajax來提交您的形式和彈出顯示結果 – Saty

回答

0

試試這個它會工作:

使用AJAX獲得此類型的功能。

的index.html:

<html> 
<head> 
<script> 
function getData(doctorid) 
    { 
      var dataString = 'doctor_id=' + doctorid; 
      $.ajax({ 
      type: "POST", 
      url: "edit-doctor.php", 
      data: dataString, 
      cache: false, 
      success: function(html) { 
        document.getElementById("get-data").innerHTML=html; 
      } 
      }); 
      return false; 
    } 
</script> 
</head> 
<body> 
<div id="get-data"></div> 
<a id="edit_docid" onClick="getData(<?php echo $tmpdocId; ?>)" href="#123" data-target="#edit_doctor" >Edit</a> 
</body> 
</html> 

編輯doctor.php:

編輯doctor.php:

<div id="edit_doctor" > 

<?php 
include("db.php"); 

    $tmpId = $_REQUEST["doctor_id"]; 

    $result = mysql_query("select * from doctor 
    where doctor_id = '$tmpId'") or die(mysql_error()); 

    $row = mysql_fetch_array($result); 
    if (!$result) 
    { 
     die("Error: Data not found.."); 
    } 

    $doctor_name = $row['doctor_name']; 
    $doctor_email = $row['doctor_email']; 
    $user_name = $row['username']; 
    $doctor_password = $row['doctor_password']; 
    $doctor_address = $row['doctor_address']; 
    $doctor_phone = $row['doctor_phone']; 
    $doctor_dept_name = $row['doctor_dept_name']; 


    if(isset($_POST['update'])) 
    { 

    $edit_doctor_name = $_POST["edit_doctor_name"]; 
    $edit_doctor_email = $_POST["edit_doctor_email"]; 
    $edit_user_name = $_POST["edit_user_name"]; 
    $edit_doctor_password = $_POST["edit_doctor_password"]; 
    $edit_doctor_address = mysql_real_escape_string($_POST['edit_doctor_address']); 
    $edit_doctor_phone = $_POST["edit_doctor_phone"]; 
    $edit_doctor_dept_name = $_POST["edit_doctor_dept_name"]; 


    $query=mysql_query("UPDATE doctor 
         SET doctor_name = '$edit_doctor_name', 
         doctor_email = '$edit_doctor_email', 
         username='$edit_user_name', 
         doctor_password = '$edit_doctor_password', 
         doctor_address = '$edit_doctor_address', 
         doctor_phone = '$edit_doctor_phone', 
         doctor_dept_name = '$edit_doctor_dept_name' 
         WHERE doctor_id = '$tmpId'") 
         or die(mysql_error()); 

    echo "<script>alert('Record Updated sucessfully...!!!!')</script>"; 

    echo "<meta http-equiv='refresh' content='0;url=disdoctor.php'>";  
    } 

mysql_close($con); 

?> 
<div class="box"> 

    <form id="form" name="registration" method="post" > 

    <table class="addtable_cls"style="margin-top:2%;margin-left: 16px;"cellspacing="1" cellpadding="10"> 
     <tr><td style="text-align:left" ><label for="name">Name<font color="red">*</font> </label></td> 
     <td ><input type="text" id="doctorName" name="edit_doctor_name" placeholder=" Name" onblur="allLetter(document.registration.fname)" required value="<?php echo $row['doctor_name']; ?>"/> 
     </td><td><img src="images2/image.png" class="masterTooltip" title="eg. Last First Middle name"></td><td style="text-align:left"><i name="nameb"style='color:red' id='unm' ></i></td></tr> 

     <tr><td style="text-align:left"> <label for="email" >Email</label></td> 
     <td ><input type="text" id="doctorEmail" name="edit_doctor_email" onblur="myfun()" placeholder="Email" required value="<?php echo $row['doctor_email']; ?>"/> 
     </td><td><img src="images2/image.png" class="masterTooltip" title="Enter valid email for eg. [email protected]"></td><td style="text-align:left"><i style='color:red' id='email' ></i></td></tr> 

     <tr ><td style="text-align:left"> <label for="uname" >User Name<font color="red">*</font></label></td> 
<td ><input type="text" id="userName" name="edit_user_name" onblur="allLetter1(document.registration.edit_user_name)" placeholder="User Name" required value="<?php echo $user_name; ?>"/> 
</td><td><img src="images2/image.png" class="masterTooltip" title="UserName contains a-z, A-Z, 0-9, _"></td><td style="text-align:left"><i name="nameb"style='color:red' id='usernm' ></i></td></tr> 


     <tr><td style="text-align:left"> <label for="password" >Password <font color="red">*</font></label></td> 
     <td ><input type="password" id="doctorPassword" name="edit_doctor_password" placeholder=" Password" onblur="passid_validation(7,20)" value="<?php echo $row['doctor_password']; ?>"/> 
     </td><td></td><td style="text-align:left"><i style='color:red' id='pass' ></i></td></tr> 


     <tr><td></td><td ><input id="sub" type="submit" name="update" value="Update Doctor" onclick="return validateDoctor()"/></td></tr> 
    </table> 
</form> 
</div> 
</div> 
相關問題