我有一个表单,我从数据库中获取数据,现在我想更新数据库。问题是,当我更新表单中的内容并按更新按钮时,它表示记录已成功更新但数据库未更新。这是我的代码
<?php
session_start();
$host="localhost";
$user="root";
$pass="";
$db="documentation";
$conn=mysqli_connect($host,$user,$pass,$db);
$off=$_GET['id'];
$result = mysqli_query($conn,"SELECT * FROM article WHERE id='". $off ."'");
if (isset($_POST['submitt']))
{
$f1 = $_POST['f1'];
$f2 = $_POST['f2'];
$f3 = $_POST['f3'];
$f4 = $_POST['f4'];
$sql= mysqli_query($conn, "UPDATE article SET sub_name='" . mysqli_real_escape_string($conn,$f2) . "', article_name='" . mysqli_real_escape_string($conn,$f3) . "', art_description='" . mysqli_real_escape_string($conn,$f4) . "', useremailll='". $_SESSION["user_mail"] ."', dateposted= NOW() WHERE id='" . mysqli_real_escape_string($conn,$f1) . "'");
if ($sql) {
echo "Record updated successfully";
header('index.php');
} else {
echo "Error updating record: " . mysqli_error($conn);
}
}
?>
<html>
<head>
<title>Edit article</title>
<link href="Content/cleditor/jquery.cleditor.css" rel="stylesheet" type="text/css" />
<link href="Content/Site.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/mystyle.css">
<script src="js/bootstrap.min.js"></script>
<script src="Scripts/jquery-1.6.3.js" type="text/javascript"></script>
<script src="Scripts/jquery.cleditor.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var options = {
width: 1150,
height: 200,
controls: "bold italic underline strikethrough subscript superscript | font size " +
"style | color highlight removeformat | bullets numbering | outdent " +
"indent | alignleft center alignright justify | undo redo | " +
"rule link image unlink | cut copy paste pastetext | print source"
};
var editor = $("#editor").cleditor(options)[0];
$("#btnClear").click(function (e) {
e.preventDefault();
editor.focus();
editor.clear();
});
$("#btnAddImage").click(function () {
editor.execCommand("insertimage", "http://images.free-extras.com/pics/s/smile-1620.JPG", null, null)
editor.focus();
});
});
</script>
</head>
<body>
<div class="container">
<div class="border3">
<div class="row">
<div class="col-md-9">
<h1><p class="margin">Edit Article</p></h1>
<p class="border1">
<p class="margin">by filling up the following form you can create a new sub-category</p>
</p>
</div>
</div>
</div>
<p class="border1"></p>
<form role="form" method="POST">
<?php
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH))
{?>
<input name='f1' value='". $id ."' type='hidden'/>
<p class="margin">
<div class="form-group" style="width: 1150px">
<label for="txt">Sub-Category Name:</label>
<input type='text' name='f2' class="form-control" id="txt" value="<?php echo $row['sub_name'];?>">
</div>
</p>
<p class="border1"></p>
<p class="margin">
<div class="form-group" style="width: 1150px">
<label for="txt">Article Name:</label>
<input type='text' name='f3' class="form-control" id="txt" value="<?php echo $row['article_name'];?>">
</div>
</p>
<p class="border1"></p>
<p class="margin">
<div style="width: 1200px">
<div>
<p><b>Description:</b></p>
<textarea id="editor" name="f4" rows="30" cols="100"><?php echo $row['art_description'];?></textarea>
</div>
<?php
}; ?>
<br/>
<div class="row">
<div class="col-md-11">
<div class="normaldiv" style="float: right">
<button type="button" class="btn btn-primary" id="btnClear">Clear</button>
<input class="btn btn-primary" type="submit" name="submitt" value="Update">
</div>
</div>
</form>
</div>
</body>
</html>
答案 0 :(得分:0)
我认为你错误地传递了id
尝试编辑此行
<input name='f1' value='". $id ."' type='hidden'/>
到
<input name='f1' value='".$row['id']."' type='hidden'/>