javascript - 如何在php中的jquery对话框弹出窗口中显示从mysql数据库中选择的记录?

标签 javascript 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. 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>

编辑-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. 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>

关于javascript - 如何在php中的jquery对话框弹出窗口中显示从mysql数据库中选择的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30232900/

相关文章:

PHPExcel 无法打开文件

php - 保存提交变量而不使用数据库?

javascript - 创建可变长度幻灯片显示的幻灯片

javascript - 页面刷新后对话框显示为 div

javascript - Node.js 事件发射器 : How to bind a class context to the event listener and then remove this listener

php - 无法从 $_POST 检索大的发布数据

javascript - 如何在TextBox中创建图案?

javascript - 折叠/展开 Accordion 时更改图像

javascript - 从实例方法调用实例方法

javascript - 从 firefox 插件公开 js 变量