PHP更新脚本中的错误 [英] Error in PHP Update Script
本文介绍了PHP更新脚本中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,从明天开始我试图通过HTML表单和PHP脚本更新我的MySql数据库,但它根本不工作-_-
这里是我的html表单代码
OK, from tomorrow I am trying to update my MySql database through HTML form and PHP script but its not working at all -_-
here is my html form code
<form role="form" action="profile_update.php">
<div class="form-group">
<label>First Name</label>
<input class="form-control" name="first_name" value="<?php echo( htmlspecialchars( $row['first_name'] ) ); ?>">
</div>
<div class="form-group">
<label>Last Name</label>
<input class="form-control" name="last_name" value="<?php echo( htmlspecialchars( $row['last_name'] ) ); ?>">
</div>
<fieldset disabled>
<div class="form-group">
<label for="disabledSelect">Username</label>
<input class="form-control" id="disabledInput" name="username" type="text" placeholder="<?php echo( htmlspecialchars( $row['username'] ) ); ?>" disabled>
</div></fieldset>
<div class="form-group">
<label>Address</label>
<textarea class="form-control" rows="3" name="address" placeholder="<?php echo( htmlspecialchars( $row['address'] ) ); ?>"></textarea>
</div>
<div class="form-group">
<label>Contact No.</label>
<input class="form-control" name="contact_no" value="<?php echo( htmlspecialchars( $row['contact_no'] ) ); ?>">
</div>
<fieldset disabled>
<div class="form-group">
<label for="disabledSelect">Email ID</label>
<input class="form-control" id="disabledInput" name="email_id" type="text" placeholder="<?php echo( htmlspecialchars( $row['email_id'] ) ); ?>" disabled>
</div></fieldset>
<fieldset disabled>
<div class="form-group">
<label for="disabledSelect">Department</label>
<input class="form-control" id="disabledInput" name="department" type="text" placeholder="<?php echo( htmlspecialchars( $row['department'] ) ); ?>" disabled>
</div></fieldset>
<button type="submit" class="btn btn-default">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</form>
</div>
这里是我的profile_update.php脚本
here is my profile_update.php script
<?php
session_start();
ob_start();
$con=mysqli_connect("localhost","root","","hct_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$first_name = mysqli_real_escape_string($con, $_POST['first_name']);
$last_name = mysqli_real_escape_string($con, $_POST['last_name']);
$address = mysqli_real_escape_string($con, $_POST['address']);
$contact_no = mysqli_real_escape_string($con, $_POST['contact_no']);
mysqli_query($con,"UPDATE admin SET first_name='$first_name', last_name='$last_name', address='$address', contact_no='contact_no'
where username= '".$_SESSION['username']."'");
mysqli_close($con);
ob_end_flush();
?>
推荐答案
row ['first_name' ])); ?> >
< / div >
< div class = form-group >
< label > 姓氏< / label >
< input class = form-contro l name = last_name value = <?php echo(htmlspecialchars(
row['first_name'] ) ); ?>"> </div> <div class="form-group"> <label>Last Name</label> <input class="form-control" name="last_name" value="<?php echo( htmlspecialchars(
row ['last_name'])); ?> >
< / div >
< fieldset 已禁用 >
< div class = form-group >
< 标签 = disabledSelect > 用户名< / label >
< 输入 class = form-control < span class =code-attribute> id = disabledInput name = 用户名 type = text 占位符 = <?php echo(htmlspecialchars(
row['last_name'] ) ); ?>"> </div> <fieldset disabled> <div class="form-group"> <label for="disabledSelect">Username</label> <input class="form-control" id="disabledInput" name="username" type="text" placeholder="<?php echo( htmlspecialchars(
row ['username'])); ?> 已停用 >
< / div > ; < / fieldset >
< div class = form-group >
< label > 地址< / label >
< textarea class = 表格控制 rows = 3 名称 = 地址 占位符 = <?php echo(htmlspecialchars(
row['username'] ) ); ?>" disabled> </div></fieldset> <div class="form-group"> <label>Address</label> <textarea class="form-control" rows="3" name="address" placeholder="<?php echo( htmlspecialchars(
这篇关于PHP更新脚本中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文