我有一个带编辑按钮的显示文件,当用户点击编辑按钮时,一个窗口应弹出数据库中的数据。
我想在我的应用程序中执行上述功能。
所以请帮助我。
以下是我的代码。
编辑按钮代码。
<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>
答案 0 :(得分: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>
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>