Php 无法更新数据库中的列
这是我的userprofile.php。我在这个页面上有更新按钮。当我点击这个按钮时,表格会隐藏,表格会显示。但是当我点击更新配置文件按钮时,它会将我重定向到这个页面,而不会在ajax.php页面中运行更新查询Php 无法更新数据库中的列,php,jquery,Php,Jquery,这是我的userprofile.php。我在这个页面上有更新按钮。当我点击这个按钮时,表格会隐藏,表格会显示。但是当我点击更新配置文件按钮时,它会将我重定向到这个页面,而不会在ajax.php页面中运行更新查询 <?php session_start(); if(isset($_SESSION['email'])) { include('config.php'); include('userheader.php')
<?php
session_start();
if(isset($_SESSION['email']))
{
include('config.php');
include('userheader.php');
include('usersiderbar.php');;
?>
<div id="page-wrapper">
<div class="col-md-12 graphs">
<div id="form4" class="xs">
<h3><strong>Your Profile</strong></h3>
<div class="bs-example4" data-example-id="simple-responsive-table">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th><strong>Name</strong></th>
<th><strong>Email</strong></th>
<th><strong>Phone Number</strong></th>
</tr>
</thead>
<tbody>
<?php
$query1=mysql_query("select * from userregister where email='".$_SESSION['email']."'");
while($query2=mysql_fetch_array($query1))
{
?>
<tr>
<th scope="row"><?php echo $query2['name'];?></th>
<td><?php echo $query2['email'];?></td>
<td><?php echo $query2['phone'];?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div><!-- /.table-responsive -->
<div style="text-align:center;"><input type="button" name="upd4" id="upd4" class="btn-success btn" value="Edit Profile" /></div>
</div>
</div>
<div id='updateprofile'>
</div>
</div>
</div>
<!-- /#page-wrapper -->
<?php
include('adminfooter.php');
}
else {
$_SESSION['invalid']=='set';
header('location:login.php');
}
?>
<script>
$(document).ready(function(){
$("#upd4").click(function(){
$.ajax({
type: "POST",
url: "ajax.php",
data: $("form").serialize(),
success: function(data) {
$("#form4").hide();
$("#updateprofile").show();
$("#updateprofile").append(data);
}
});
});
});
</script>
您的个人资料
名称
电子邮件
电话号码
这个按钮从来没有贴过。所以if(isset($\u POST['updatenew']){}
永远不会为真
将其更改为表单的必填字段的名称。例如:if(isset($\u POST['name']){}
请在表单中添加新行
<div class="tab-content">
<div class="tab-pane active" id="horizontal-form">
<form class="form-horizontal" action="" method="post">
<input type="hidden" name="updatenew" value="Update Profile" />
<div class="form-group">
<label class="col-sm-2 control-label">Name :- </label>
<div class="col-sm-8">
<input type="text" name="name" id="name" class="form-control1" value="<?php echo $row2['name']; ?>" tabindex="1" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Email :- </label>
<div class="col-sm-8">
<input type="text" name="email" id="email" class="form-control1" value="<?php echo $row2['email']; ?>" tabindex="1" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Phone Number :- </label>
<div class="col-sm-8">
<input type="text" name="phone" id="phone" class="form-control1" value="<?php echo $row2['phone']; ?>" tabindex="1" />
</div>
</div>
<div style="text-align:center;"><button class="btn-success btn" name="updatenew" id="updatenew">Update Profile</button></div>
</form>
</div>
</div>
<script>
$(document).on("click", "#updatenew", function(){
$.ajax({
type: "POST",
url: "ajax.php",
data: $("form").serialize(),
success: function(data) {
alert(data);
$("#updateprofile").hide();
}
});
});
</script>
姓名:-
您将清理这些输入并为mysqli或PDO交换mysql\u query
,对吗?显示任何错误?不,它没有显示任何错误。在执行之前,$sql
实际设置了什么?停止使用mysql\u
,如果这是一个学校项目,你需要紧急告诉你的导师,MySQL\uquot/code>已被弃用,他们应该使用MySQLi\uquot/code>或PDO
,在那里我必须添加这个按钮。@Prateik.In ajax.php或userregister.php。它应该在userregister.php表单tagin userregister.php之后。我没有任何类型的表单。它只是在表中显示数据。@prateik.see我已经更新了答案,您应该像我在您的代码中一样放置隐藏字段。:)谢谢,但是我已经放置了隐藏按钮,并且我已经更改了表单中的按钮名称。但是它没有显示任何结果。@prateik.this是我的ajax.php。因此我想我只运行一次。我将单击该按钮,它将重定向到我有ajax的主页。
<div class="tab-content">
<div class="tab-pane active" id="horizontal-form">
<form class="form-horizontal" action="" method="post">
<input type="hidden" name="updatenew" value="Update Profile" />
<div class="form-group">
<label class="col-sm-2 control-label">Name :- </label>
<div class="col-sm-8">
<input type="text" name="name" id="name" class="form-control1" value="<?php echo $row2['name']; ?>" tabindex="1" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Email :- </label>
<div class="col-sm-8">
<input type="text" name="email" id="email" class="form-control1" value="<?php echo $row2['email']; ?>" tabindex="1" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Phone Number :- </label>
<div class="col-sm-8">
<input type="text" name="phone" id="phone" class="form-control1" value="<?php echo $row2['phone']; ?>" tabindex="1" />
</div>
</div>
<div style="text-align:center;"><button class="btn-success btn" name="updatenew" id="updatenew">Update Profile</button></div>
</form>
</div>
</div>
<script>
$(document).on("click", "#updatenew", function(){
$.ajax({
type: "POST",
url: "ajax.php",
data: $("form").serialize(),
success: function(data) {
alert(data);
$("#updateprofile").hide();
}
});
});
</script>