Php 通过ajax从数据库检索数据
我已经创建了一个页面form.php。很好用。当我点击更新按钮时,它以Php 通过ajax从数据库检索数据,php,ajax,Php,Ajax,我已经创建了一个页面form.php。很好用。当我点击更新按钮时,它以 液体 用户名 电子邮件地址 性别 出生日期 编辑 删除 Form.php <?php include 'config.php'; error_reporting(0); //include 'edit.php'; if(isset($_GET['uid'])) { $userid = $_GET['uid'];
液体
用户名
电子邮件地址
性别
出生日期
编辑
删除
Form.php
<?php
include 'config.php';
error_reporting(0);
//include 'edit.php';
if(isset($_GET['uid']))
{
$userid = $_GET['uid'];
$result = mysqli_query($con,"select * from u_reg where u_id={$userid}");
$row = mysqli_fetch_array($result);
}
?>
<!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 charset="utf-8">
<title>Registration Form</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<link rel="stylesheet" href="css/main.css">
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript"src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.js"></script>
<script type="text/javascript" src="js/validation_form.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="js/statecountry.js"></script>
<script>
$(function() {
$( "#datepicker") .datepicker({changeMonth: true,
changeYear: true,
yearRange:"-100:+0"});
});
</script>
</head>
<body>
<div class="container">
<?php
if(isset($_GET['uid']))
{
if ($_GET['uid']!='')
{
echo'<form action="con-edit-user.php?userid='.$row["u_id"].'" id="myForm" method="post" enctype="multipart/form-data" >';
} }
else {
echo '<form action="userclass.php" id="myForm1" method="post" enctype="multipart/form-data" >';
}
?>
<!--<form action="userclass.php" method="post" enctype="multipart/form-data" id="example1" > -->
<label id="dis" ></label><br>
<input type="hidden" name="userid" value="<?php echo($userid); ?>">
<div class="image1" >
<?php
if(isset($row['u_image']))
{
echo"<img src='".$row['u_image']."'> ";
}
?>
</div>
<table align="center" cellspacing="14" >
<tr>
<td colspan="2">
<h1 align="center">Registration Form</h1>
</td>
</tr>
<tr>
<td><label>
User Name:</label></td>
<td><input type="text" name="uname" id="uname" value="<?php if(isset($row['u_name'])) echo($row['u_name']); ?>">
<td id="nameerror"></td>
</td>
</tr>
<tr>
<td>
<label>Gender:</label></td><td id ="gen">
<input type="radio" name="gender" value="M" <?php if(isset($row['u_gender'])) if($row['u_gender']=="M"){echo("checked='checked'");} ?> id="gender" /> <strong>Male</strong>
<input type="radio" name="gender" value="F" <?php if(isset($row['u_gender'])) if($row['u_gender']=="F"){echo("checked='checked'");}?>id="gender" /> <strong>Female</strong>
<td id="gendererror"></td>
</td>
</tr>
<tr>
<td>
<label>Email:</label></td><td> <input type="text" name="email" id="email" value="<?php if(isset($row['u_mail'])) echo($row['u_mail']); ?>"/>
</td>
<td id="emailerror"></td>
</tr>
<tr>
<td>
<label>Password:</label><td> <input type="password" name="pwd" id="pwd"value="<?php if(isset($row['u_pwd'])) echo($row['u_pwd']); ?>" />
<td id="pwderror"></td>
</td>
</tr>
<tr>
<td>
<label>Date Of Birth:</label><td> <input type="text" required name="DOB" id="datepicker"value="<?php if(isset($row['u_dob'])) echo($row['u_dob']); ?>" />
<td id="doberror"></td>
</td>
</tr>
<?php
$sql = "SELECT * FROM country_master ORDER BY c_name";
$query = mysqli_query($con, $sql);
?>
<td><label>Country :</label></td>
<td><select name="country" class="country" id="in">
<option value="select">---Select---</option>
<?php while ($row1 = mysqli_fetch_array($query)) { ?>
<option value="<?php echo $row1["c_id"]; ?>" <?php if($row1["c_id"] == $row['u_country']){ echo "selected=selected"; } ?> ><?php echo $row1["c_name"]; ?></option>
<?php } ?>
<td id="conerror"></td>
<!--<option value="india">India</option>
<option value="usa">USA</option>-->
</select>
</td>
</tr>
<tr>
<?php
$sql = "SELECT * FROM state_master ORDER BY s_name";
$query = mysqli_query($con, $sql);
?>
<td><label>State :</label></td>
<td><select name="state1" class="state" selected="selected">
<option value="select">---Select---</option>
<?php while ($row1 = mysqli_fetch_array($query)) { ?>
<option value="<?php echo $row1["s_id"]; ?>" <?php if($row1["s_id"] == $row['u_state']){ echo "selected=selected"; } ?> ><?php echo $row1["s_name"]; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>
<label>Hobbies:</label></td><td id="ck1">
<?php
$hobbies = explode(" ",$row['u_hobbies']);
?>
<input type="checkbox" value="CR" <?php if(in_array("CR",$hobbies)) { echo "checked=checked"; } ?> name="hobbies1" id="ck" <?php if(isset($_POST['hobbies'])){
$check1='selected'; echo $check1; } ?><?php if($row['u_hobbies']=="CR"){echo("checked='checked'");} ?> /> Cricket
<input type="checkbox" value="FO" <?php if(in_array("FO",$hobbies)) { echo "checked=checked"; } ?>name="hobbies2" id="ck" <?php if(isset($_POST['hobbies'])){
$check2='selected'; echo $check2; } ?><?php if($row['u_hobbies']=="FO"){echo("checked='checked'");} ?> /> Football<br />
<input type="checkbox" value="RE" <?php if(in_array("RE",$hobbies)) { echo "checked=checked"; } ?>name="hobbies3" id="ck" <?php if(isset($_POST['hobbies'])){
$check3='selected'; echo $check3; } ?><?php if($row['u_hobbies']=="RE"){echo("checked='checked'");} ?> /> Reading
<input type="checkbox" value="PL" <?php if(in_array("PL",$hobbies)) { echo "checked=checked"; } ?>name="hobbies4" id="ck" <?php if(isset($_POST['hobbies'])){
$check4='selected'; echo $check4; } ?><?php if($row['u_hobbies']=="PL"){echo("checked='checked'");} ?> /> Playing Games
</td>
<td id="ckerror"></td>
</tr>
<tr>
<td>
<label> Photo Upload:</label></td>
<td><input type="file" name="image" id="img1" />
<td><div>
<?php
if(isset($row[' u_image']))
{
echo"<img src='".$row[' u_image']."'> ";
}
?>
</div>
</td>
</tr>
<tr>
<td><label>
About You:</label></td>
<td><textarea name="about" id="ek"></textarea></td>
<td id="ekerror">
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Submit" id="submit" />
<input type="reset" name="reset" value="Reset" id="reset"/>
<a href= "index.php"id="cancel"> <input type="button" name="cancel" value="Cancel" id="cancel"/></a> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
登记表
$(函数(){
$(“#datepicker”).datepicker({changeMonth:true,
变化年:是的,
年份范围:“-100:+0”});
});
阅读教程,向我展示一些代码,以便我们可以进行指导you@sandeep_kosta我已经编辑了你的简历。对于代码,我是ajax的初学者,我不知道怎么做。我敦促你先学习它,因为你是新手,请看@HarshitShrivastava评论。。首先学习它,如果有任何问题,请在这里提问。。。我们很乐意解决这个问题
<?php
include 'config.php';
error_reporting(0);
//include 'edit.php';
if(isset($_GET['uid']))
{
$userid = $_GET['uid'];
$result = mysqli_query($con,"select * from u_reg where u_id={$userid}");
$row = mysqli_fetch_array($result);
}
?>
<!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 charset="utf-8">
<title>Registration Form</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<link rel="stylesheet" href="css/main.css">
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript"src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.js"></script>
<script type="text/javascript" src="js/validation_form.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="js/statecountry.js"></script>
<script>
$(function() {
$( "#datepicker") .datepicker({changeMonth: true,
changeYear: true,
yearRange:"-100:+0"});
});
</script>
</head>
<body>
<div class="container">
<?php
if(isset($_GET['uid']))
{
if ($_GET['uid']!='')
{
echo'<form action="con-edit-user.php?userid='.$row["u_id"].'" id="myForm" method="post" enctype="multipart/form-data" >';
} }
else {
echo '<form action="userclass.php" id="myForm1" method="post" enctype="multipart/form-data" >';
}
?>
<!--<form action="userclass.php" method="post" enctype="multipart/form-data" id="example1" > -->
<label id="dis" ></label><br>
<input type="hidden" name="userid" value="<?php echo($userid); ?>">
<div class="image1" >
<?php
if(isset($row['u_image']))
{
echo"<img src='".$row['u_image']."'> ";
}
?>
</div>
<table align="center" cellspacing="14" >
<tr>
<td colspan="2">
<h1 align="center">Registration Form</h1>
</td>
</tr>
<tr>
<td><label>
User Name:</label></td>
<td><input type="text" name="uname" id="uname" value="<?php if(isset($row['u_name'])) echo($row['u_name']); ?>">
<td id="nameerror"></td>
</td>
</tr>
<tr>
<td>
<label>Gender:</label></td><td id ="gen">
<input type="radio" name="gender" value="M" <?php if(isset($row['u_gender'])) if($row['u_gender']=="M"){echo("checked='checked'");} ?> id="gender" /> <strong>Male</strong>
<input type="radio" name="gender" value="F" <?php if(isset($row['u_gender'])) if($row['u_gender']=="F"){echo("checked='checked'");}?>id="gender" /> <strong>Female</strong>
<td id="gendererror"></td>
</td>
</tr>
<tr>
<td>
<label>Email:</label></td><td> <input type="text" name="email" id="email" value="<?php if(isset($row['u_mail'])) echo($row['u_mail']); ?>"/>
</td>
<td id="emailerror"></td>
</tr>
<tr>
<td>
<label>Password:</label><td> <input type="password" name="pwd" id="pwd"value="<?php if(isset($row['u_pwd'])) echo($row['u_pwd']); ?>" />
<td id="pwderror"></td>
</td>
</tr>
<tr>
<td>
<label>Date Of Birth:</label><td> <input type="text" required name="DOB" id="datepicker"value="<?php if(isset($row['u_dob'])) echo($row['u_dob']); ?>" />
<td id="doberror"></td>
</td>
</tr>
<?php
$sql = "SELECT * FROM country_master ORDER BY c_name";
$query = mysqli_query($con, $sql);
?>
<td><label>Country :</label></td>
<td><select name="country" class="country" id="in">
<option value="select">---Select---</option>
<?php while ($row1 = mysqli_fetch_array($query)) { ?>
<option value="<?php echo $row1["c_id"]; ?>" <?php if($row1["c_id"] == $row['u_country']){ echo "selected=selected"; } ?> ><?php echo $row1["c_name"]; ?></option>
<?php } ?>
<td id="conerror"></td>
<!--<option value="india">India</option>
<option value="usa">USA</option>-->
</select>
</td>
</tr>
<tr>
<?php
$sql = "SELECT * FROM state_master ORDER BY s_name";
$query = mysqli_query($con, $sql);
?>
<td><label>State :</label></td>
<td><select name="state1" class="state" selected="selected">
<option value="select">---Select---</option>
<?php while ($row1 = mysqli_fetch_array($query)) { ?>
<option value="<?php echo $row1["s_id"]; ?>" <?php if($row1["s_id"] == $row['u_state']){ echo "selected=selected"; } ?> ><?php echo $row1["s_name"]; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>
<label>Hobbies:</label></td><td id="ck1">
<?php
$hobbies = explode(" ",$row['u_hobbies']);
?>
<input type="checkbox" value="CR" <?php if(in_array("CR",$hobbies)) { echo "checked=checked"; } ?> name="hobbies1" id="ck" <?php if(isset($_POST['hobbies'])){
$check1='selected'; echo $check1; } ?><?php if($row['u_hobbies']=="CR"){echo("checked='checked'");} ?> /> Cricket
<input type="checkbox" value="FO" <?php if(in_array("FO",$hobbies)) { echo "checked=checked"; } ?>name="hobbies2" id="ck" <?php if(isset($_POST['hobbies'])){
$check2='selected'; echo $check2; } ?><?php if($row['u_hobbies']=="FO"){echo("checked='checked'");} ?> /> Football<br />
<input type="checkbox" value="RE" <?php if(in_array("RE",$hobbies)) { echo "checked=checked"; } ?>name="hobbies3" id="ck" <?php if(isset($_POST['hobbies'])){
$check3='selected'; echo $check3; } ?><?php if($row['u_hobbies']=="RE"){echo("checked='checked'");} ?> /> Reading
<input type="checkbox" value="PL" <?php if(in_array("PL",$hobbies)) { echo "checked=checked"; } ?>name="hobbies4" id="ck" <?php if(isset($_POST['hobbies'])){
$check4='selected'; echo $check4; } ?><?php if($row['u_hobbies']=="PL"){echo("checked='checked'");} ?> /> Playing Games
</td>
<td id="ckerror"></td>
</tr>
<tr>
<td>
<label> Photo Upload:</label></td>
<td><input type="file" name="image" id="img1" />
<td><div>
<?php
if(isset($row[' u_image']))
{
echo"<img src='".$row[' u_image']."'> ";
}
?>
</div>
</td>
</tr>
<tr>
<td><label>
About You:</label></td>
<td><textarea name="about" id="ek"></textarea></td>
<td id="ekerror">
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Submit" id="submit" />
<input type="reset" name="reset" value="Reset" id="reset"/>
<a href= "index.php"id="cancel"> <input type="button" name="cancel" value="Cancel" id="cancel"/></a> </td>
</tr>
</table>
</form>
</div>
</body>
</html>