我试图完成我的新的个人CMS(内容管理系统),我已经编程了一个部分,其中包括插入,选择和删除项目在一个页面与PHP,MySql和引导模式。显然,我在更新查询方面有问题。过程是当我点击编辑按钮,模态引导将显示,然后关联数据将检索表格Mysql的值属性。之后,我改变他们,并点击提交按钮。问题就在这里!当进程完成时,我的$_POST‘’input_ complete‘中会出现错误。var_dump获得NULL,最后我有未定义的索引。有谁能解决这个问题吗?谢谢你们所有人。下面是我使用PHP的模式引导代码:
<?php
$selectForUpdate = "SELECT * FROM ring WHERE id='4'";
$resultSelectForUpdate = mysqli_query($connect_to_db, $selectForUpdate);
$first = $second = $third= '';
$first = $_POST['u_ringCode'];
$second = $_POST['u_ringWeight'];
$third = $_POST['u_ringComment'];
$updateQuery = "UPDATE ring SET ring_code='".$first."', ring_weight='".$second."', ring_comment='".$third."' WHERE id='4'";
$resultUpdateQuery = mysqli_query($connect_to_db, $updateQuery);
while ( $showUpdateRows = mysqli_fetch_assoc( $resultSelectForUpdate ) ) {
?>
<!-- Update Modal -->
<div class="modal fade bs-example-modal-sm" id="update-4" tabindex="-1" role="dialog" aria-labelledby="update-4-label" >
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h5 class="modal-title text-center" id="update-4-label" style="color:#ddd;" >
Edit Code
</h5>
</div>
<div class="modal-body">
<div class="col-md-12 col-sm-12 col-xs-12">
<form method="post" action="<?=htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="form-group">
<label for="">Ring Code :</label>
<input type="text" class="form-control" id="" name="u_ringCode" placeholder="" value="<?=$showUpdateRows['ring_code']?>">
</div>
<div class="form-group">
<label for="">Ring Weight :</label>
<input type="text" class="form-control" id="" name="u_ringWeight" placeholder="" value="<?=$showUpdateRows['ring_weight']?>">
</div>
<div class="form-group">
<label for="">Comment :</label>
<input type="text" class="form-control" id="" name="u_ringComment" placeholder="" value="<?=$showUpdateRows['ring_comment']?>">
</div>
</form>
</div>
</div>
<div class="modal-footer">
<a type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
<a type="submit" class="btn btn-default pull-left" name="ringDelete" style="color:black;" href="?update=4">Submit</a>
</div>
</div>
</div>
</div>
<?php
}
?>发布于 2016-06-09 07:14:12
<?php
/*Code Start For Connnect Database*/
$connect_to_db=mysqli_connect("localhost", "root", "", "db_name" );
/*Code End For Connnect Database*/
/*Code Start For Update Modal Form*/
if (isset($_REQUEST['ringUpdate'])) {
$first = $_POST['u_ringCode'];
$second = $_POST['u_ringWeight'];
$third = $_POST['u_ringComment'];
$updateQuery = "UPDATE ring SET ring_code='".$first."', ring_weight='".$second."', ring_comment='".$third."' WHERE id='4'";
$resultUpdateQuery = mysqli_query($connect_to_db, $updateQuery);
}
/*Code End For Update Modal Form*/
$selectForUpdate = "SELECT * FROM ring WHERE id='4'";
$resultSelectForUpdate = mysqli_query($connect_to_db, $selectForUpdate);
while ( $showUpdateRows = mysqli_fetch_assoc( $resultSelectForUpdate ) ) {
?>
<!-- Update Modal -->
<div class="modal fade bs-example-modal-sm" id="update-4" tabindex="-1" role="dialog" aria-labelledby="update-4-label" >
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<form method="post" action="<?=htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h5 class="modal-title text-center" id="update-4-label" style="color:#ddd;" >
Edit Code
</h5>
</div>
<div class="modal-body">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="form-group">
<label for="">Ring Code :</label>
<input type="text" class="form-control" id="" name="u_ringCode" placeholder="" value="<?=$showUpdateRows['ring_code']?>">
</div>
<div class="form-group">
<label for="">Ring Weight :</label>
<input type="text" class="form-control" id="" name="u_ringWeight" placeholder="" value="<?=$showUpdateRows['ring_weight']?>">
</div>
<div class="form-group">
<label for="">Comment :</label>
<input type="text" class="form-control" id="" name="u_ringComment" placeholder="" value="<?=$showUpdateRows['ring_comment']?>">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
<input type="submit" class="btn btn-default pull-left" name="ringUpdate" style="color:black;" value="submit">
</div>
</form>
</div>
</div>
</div>
<?php
}
?>发布于 2016-06-09 06:48:11
您的$_POST变量在表单提交之前为空。你得检查一下这个。此外,在不转义字符串的情况下进行db查询也是不安全的。您可以通过搜索MySQL注入来阅读更多有关此信息的内容。第三件事是在更新查询之前获取项。在这种情况下,您将在页面刷新后在page.Only上看到未更改的数据,它将显示新的值。代码的第一部分可能如下所示:
<?php
if(!empty($_POST['u_ringCode'])&&!empty($_POST['u_ringWeight'])&&!empty($_POST['u_ringComment']))
{
$first = $connect_to_db->escape_string($_POST['u_ringCode']);
$second = $connect_to_db->escape_string($_POST['u_ringWeight']);
$third = $connect_to_db->escape_string($_POST['u_ringComment']);
$updateQuery = "UPDATE ring SET ring_code='$first', ring_weight='$second', ring_comment='$third' WHERE id='4'";
$resultUpdateQuery = mysqli_query($connect_to_db, $updateQuery);
}
$selectForUpdate = "SELECT * FROM ring WHERE id='4'";
$resultSelectForUpdate = mysqli_query($connect_to_db, $selectForUpdate);
while ( $showUpdateRows = mysqli_fetch_assoc( $resultSelectForUpdate ) ) {
?>https://stackoverflow.com/questions/37718313
复制相似问题