我试图创建一个更新新闻脚本,其中可以选择数据库条目并将此选择还原到名为updatenews.php的新php页面,该页面需要显示带有消息的textarea和带日期的textarea。按下更新后,此条目应更新到数据库中。
我确实设法让我的脚本上传新闻消息的方式是它加载一个显示上传然后重新加载到上一页的新页面,以及一个删除从数据库中选择的消息的部分。那些像沙姆一样工作
我想以某种方式使用相同的东西,但是当updatenews.php页面被加载时,它会加载HTML部分,但不会显示上一页上选择的条目。
我如何获取"结果"从上一页的选择到新页面,并使脚本记住按下更新按钮时的ID?
这是我对显示选择了删除或更新的数据库条目的页面所具有的:
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
// Get our database connector
require("includes/conn.php");
?>
<?php
if(isset($_POST['update'])){ // Check update button is clicked
foreach($_POST['checkbox'] as $update_id){ // loop only checked items and load update page
$sql = "SELECT FROM news WHERE id='$update_id'";
$result = mysqli_query($conn, $sql);
echo "De update pagina wordt in 5 seconden geladen.";
header('Refresh: 5; url=updatenews.php');
}
}
?>
<?php
if(isset($_POST['delete'])){ // Check delete button is clicked
foreach($_POST['checkbox'] as $del_id){ // loop only checked items and delete
$sql = "DELETE FROM news WHERE id='$del_id'";
$result = mysqli_query($conn, $sql);
}
}
?>
<?php
$result=mysqli_query($conn, "SELECT * FROM news ORDER BY ID");
$count=mysqli_num_rows($result);
?>
<!DOCTYPE html>
<html>
<head>
<title>Upload Multiple Images Using jquery and PHP</title>
<!------- Including CSS File ------>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div align="center">
<table background="transparent" width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Selecteer welke berichten verwijderd moeten worden.</strong></td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Datum</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>news post</strong></td>
</tr>
<?php
while($rows=mysqli_fetch_array($result)){
echo "<div class=\"picture\">";
echo "<p>";
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['date']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['news']; ?></td>
</tr>
<?php
echo "</p>";
echo "</div>";
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"><input name="update" type="submit" id="update" value="Update"></td>
</tr>
<?php
// Check if delete button active, start this
mysqli_close($conn);
?>
</table>
</form>
</td>
</tr>
</table>
<a href="newsupload.php" title="Back">Back</a>
</div>
</body>
</html>
&#13;
这是加载的updatenews.php页面:
<?php
session_start(); /// initialize session
include("important/passwords.php");
check_logged(); /// function checks if visitor is logged. If user is not logged the user is redirected to login.php page
// Start a session for displaying any form errors
session_start();
?>
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
// Get our database connector
require("includes/conn.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>Upload Multiple Images Using jquery and PHP</title>
<!------- Including CSS File ------>
<link rel="stylesheet" type="text/css" href="style.css">
<style type="text/css">
label
{
float: left;
text-align: right;
margin-right: 10px;
width: 100px;
color: black;
}
#submit
{
float: left;
margin-top: 5px;
position: relative;
left: 43%;
}
#error
{
color: red;
font-weight: bold;
font-size: 16pt;
}
</style>
</head>
<body>
<div id="maindiv">
<div id="formdiv">
<h2 align="center">Update nieuws</h2>
<?php
if (isset($_SESSION['error']))
{
echo "<span id=\"error\"><p>" . $_SESSION['error'] . "</p></span>";
unset($_SESSION['error']);
}
$query="UPDATE into news (date, news) values ('$date', '$news')";
?>
<form action="upload.php" method="post" enctype="multipart/form-data">
<label>Datum:</label>
<input type="text" name="date" style="width:250px;" value="<?php echo 'date'; ?>"/><br />
<label>Nieuws:</label>
<textarea name="news" style="width:250px;height:150px;" value="<?php echo 'news'; ?>" ></textarea><br /><br />
<input type="submit" value="Update" name="submit" id="submit" class="upload" />
</p>
</form>
<form action="logout.php" method="post" class="textdelete">
<input type="submit" name="formSubmit" value="Logout" />
</form>
</p>
</div>
</div>
</body>
</html>
&#13;
我认为问题在于我获取结果的方式并尝试将它们转到updatenews.php页面,但我似乎无法弄清楚我出错的方式或地点因为我我很喜欢php编码...
答案 0 :(得分:0)
To get your results passed on to the "updatenews.php
" page, you need to pass the "$update_id
" variable in your URL like this: "updatenews.php?id=$update_id
"
And then in your "updatenews.php", you retrieve the "$update_id
" value like this: "$retrieve_id = $_GET['id'];
"
Hope this helps you out !