我创建了一个名为editor的数据库和名为editorNB的表。我在这篇文章中附上了我的表格细节。 我也附上我的php文件和html文件。
问题:我遇到的问题是我是abeto插入并删除了这段代码,但是当我更新它直接发送到我想要去“成功更新”的页面。但它不是udpating。一点都不
字段类型空键默认额外 user_uid varchar(256)NO NULL subject varchar(300)NO NULL 内容文本NO NULL entry_id int(11)NO PRI NULL auto_increment 日期日期NO NULL
<?php
session_start();
if ($_SESSION['u_uid']) {
} else {
header("location: http://localhost/Project%20NB/signupnb.php");
exit();
}
$user = $_SESSION['u_uid'];
$subject = "";
$entry = "";
$update = FALSE;
$id = 0;
if (isset($_POST['submit'])) {
$date = date("M/d/y");
$subject = $_POST['subject'];
$entry = $_POST['editor'];
$conn2 = mysqli_connect("localhost", "root", "") or die(mysql_error());
mysqli_Select_db($conn2, "editor") or die("connot connect to the database");
$stmt = mysqli_prepare($conn2, "INSERT INTO `editornb` (`user_uid`,`subject`, `content`, `date`) values ('" . $user . "','" . $subject . "','" . $entry . "','" . $date . "')");
$er = mysqli_stmt_execute($stmt);
if ($er == TRUE) {
print '<script> alert("Sucessfully Inserted!!!");</script>';
header("location:http://localhost/Project%20NB/projectNB.php");
} else {
header("location:http://localhost/Project%20NB/projectNB.php");
exit();
}
}
if (isset($_POST['update'])) {
$id = $_POST['edit'];
$subject = $_POST['subject'];
$content = $_POST['editor'];
$conn2 = mysqli_connect("localhost", "root", "") or die(mysql_error());
mysqli_Select_db($conn2, "editor") or die("connot connect to the database");
$updatenew = "UPDATE `editornb` SET content='" . $content . "',`subject`='" . $subject . "' WHERE entry_id='" . $id . "'";
$query = mysqli_query($conn2, $updatenew);
$er = mysqli_stmt_execute($stmt);
if ($query == TRUE) {
print '<script> alert("Sucessfully updated!!!");</script>';
header("location:http://localhost/Project%20NB/projectNB.php");
} else {
header("location:http://localhost/Project%20NB/editor/temptextarea.php");
exit();
}
}
if (isset($_GET['delid'])) {
$id = $_GET['delid'];
$sql = "DELETE FROM editornb WHERE entry_id= '$id' ";
$answer = mysqli_query($conn2, $sql);
print '<script> alert("Sucessfully deleted!!!");</script>';
}
session_abort();
<?php
$conn2=mysqli_connect("localhost","root","") or die(mysql_error());
mysqli_select_db($conn2,"editor") or die("connot connect to the database");
include('php_file.php');
session_start();
if(isset($_GET['edit'])) {
$id = $_GET['edit'];
$update = TRUE;
$query = "SELECT * from `editornb` where entry_id='$id'";
$result = mysqli_query($conn2, $query);
if (count($result) == 1) {
$n = mysqli_fetch_array($result);
$subject = $n['subject'];
$content = $n['content'];
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title> CK EDITOR </title>
<link rel="stylesheet" type="text/css" href="http://localhost/Project%20NB/editor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="http://localhost/Project%20NB/editor/fontawesome/fontawesome-free-5.0.6/web-fonts-with-css/css/fontawesome.min.css">
<script type="text/javascript" src="http://localhost/Project%20NB/editor/ckeditor/ckeditor/ckeditor.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
</head>
<body>
<br>
<a class="btn btn-success" href="http://localhost/Project%20NB/editor/textareaNB.php"> Home </a>
<br>
<form action="http://localhost/Project%20NB/editor/php_file.php" method="POST" id="editorForm">
<input type="text" name="subject" value="<?php echo $subject; ?>">
<textarea class="ckeditor" id="editor" name="editor"><?php if(isset($content)) echo $content; ?></textarea>
<br>
<?php if ($update == true): ?>
<button type="submit" name="update" class="btn btn-sucess">Update</button>
<?php else: ?>
<button type="submit" name="submit" class="btn btn-sucess">Submit</button>
<?php endif ?>
</form>
<?php
if (isset($alertMessage))
echo $alertMessage;
?>
<br>
<div class="search">
<form method="post" action="search_go.php" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
</form>
</div>
<br><br>
<table class="table table-striped table-bordered" id="table">
<tr>
<th> ID</i></a></th>
<th> DATE</th>
<th> Subject</th>
<th> Update</th>
<th> Delete</th>
</tr>
<?php
$count = 1;
$user = ($_SESSION['u_uid']);
$query = "SELECT * FROM `editornb` where user_uid='".$user."'";
$result = mysqli_query($conn2, $query);
$result_check = mysqli_num_rows ($result);
$date = date("M/d/y");
if ($result_check > 0) {
while ($row= mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" .$count."</td>";
echo "<td>" .$row["date"]. "</td>";
echo "<td>" .$row["subject"]."</td>";
echo '<td><a href="http://localhost/Project%20NB/editor/temptextarea.php?edit='.$row['entry_id'].'" type="button" class="btn btn-primary btn-sm">
<span class="fa fa-edit"></span> </a></td>';
echo '<td><a href="http://localhost/Project%20NB/editor/php_file.php?delid='.$row['entry_id'].'" type="button" class="btn btn-danger btn-sm">
</a></td>';
echo "</tr>";
$count++;
}
}
?>
</table>
</body>
</html>