... SOOOOO
为什么这不会将内容更改为我的数据库?
<?php
if(isset($_POST['submit']))
{
if( isset($_POST['post_body']) )
{
$post_body = $_POST['post_body'];
$id = $_POST['id'];
$sql = "UPDATE forum_post SET post_body='$post_body' WHERE post_id='$id'";
$res = mysqli_query($mysql, $sql);
}
if( isset($_POST['post_title']) )
{
$post_title = $_POST['post_title'];
$id = $_POST['id'];
$sql = "UPDATE forum_post SET post_title='$post_title' WHERE post_id='$id'";
$res = mysqli_query($mysql, $sql);
}
}
?>
&#13;
<form action="<?php $_PHP_SELF ?>" method="POST" class="form-horizontal">
<fieldset>
<legend>Edit</legend>
<div class="form-group">
<input type="hidden" name="id" value="<?php echo $post_id; ?>">
<label for="inputTitle" class="col-lg-2 control-label">Title</label>
<div class="col-lg-5">
<input type="text" class="form-control" id="post_title" name="post_title" placeholder="<?php echo $post_title; ?>" value="<?php echo $post_title; ?>">
</div>
</div>
<div class="form-group">
<label for="inputTitle" class="col-lg-2 control-label">Created</label>
<div class="col-lg-5">
<p><?php echo $post_created;?></p>
</div>
</div>
<div class="form-group">
<label for="textArea" class="col-lg-2 control-label">Textarea</label>
<div class="col-lg-10">
<textarea type="text" name="post_body" id="post_body" rows="8" class="col-md-12" value="<?php echo $post_body; ?>" class="form-control" rows="3">
<?php echo $post_body; ?>
</textarea>
<span class="help-block">Here goes the content.</span>
</div>
<div class="col-md-2"><a href class="col-md-2 btn btn-danger btn-block" ng-show="showme" ng-click="showme=false">Back</a></div>
<input class="pull-right col-md-10 btn btn-primary btn-default" id="submit" type="submit" value="Submit" name="submit"/>
</div>
</fieldset>
</form>
&#13;
我想要更新我的帖子内容&amp;现在的头衔。 为什么这不更新我的数据库? 我什么也看不到错误。
我可以填写表格,按更新,没有错误。 控制台也是空的。
问题是什么?
答案 0 :(得分:0)
你必须逃避你的价值观。
$sql = "UPDATE forum_post SET post_body='$post_body' WHERE post_id='$id'";
可能是:
$sql = "UPDATE forum_post SET post_body='".$post_body."' WHERE post_id='".$id."'";
关于注射的警告!
答案 1 :(得分:0)
尝试像这样回应错误mysql_error()
<?php
if(isset($_POST['submit']))
{
if( isset($_POST['post_body']) )
{
$post_body = $_POST['post_body'];
$id = $_POST['id'];
$sql = "UPDATE forum_post SET post_body='$post_body' WHERE post_id='$id'";
$res = mysqli_query($mysql, $sql);
if($res)
{
echo "updated";
} else
{
echo mysqli_error();
}
}
if( isset($_POST['post_title']) )
{
$post_title = $_POST['post_title'];
$id = $_POST['id'];
$sql = "UPDATE forum_post SET post_title='$post_title' WHERE post_id='$id'";
$res = mysqli_query($mysql, $sql);
if($res)
{
echo "updated";
} else
{
echo mysqli_error();
}
}
}
?>