簡體   English   中英

如何顯示在php的jquery對話框彈出窗口中從mysql數據庫中選擇的記錄?

[英]how to display records selected from mysql database in jquery dialog popup in php.?

我有一個帶有編輯按鈕的顯示文件,當用戶單擊編輯按鈕時,應該彈出一個窗口,其中包含來自數據庫的數據。

我想在應用程序中完成上述書面功能。

所以請幫幫我。

這是下面的代碼。

編輯按鈕代碼。

<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. abcd@example.com"></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>

試試這個將起作用:

使用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>

edit-doctor.php:

edit-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. abcd@example.com"></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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM