从列表框中获取所选索引id并在另一个页面上获取id的php代码
表名---新闻 我创建了两页 1) sethomepage.php 2) exec_setpage.php从列表框中获取所选索引id并在另一个页面上获取id的php代码,php,Php,表名---新闻 我创建了两页 1) sethomepage.php 2) exec_setpage.php $id = $_POST['sel_news']; //Get the value of selected option 我创建了一个列表框,并从sethomepage.php上的数据库中填充它 现在我需要将所选值的id从listbox传递到exec_setpage.php 下面是我的代码 请建议我如何获取选定值索引并进入另一页。 bcoz它向我显示错误未定义的索引id s
$id = $_POST['sel_news']; //Get the value of selected option
我创建了一个列表框,并从sethomepage.php上的数据库中填充它
现在我需要将所选值的id从listbox传递到exec_setpage.php
下面是我的代码
请建议我如何获取选定值索引并进入另一页。
bcoz它向我显示错误未定义的索引id
sethomepage.php代码
<select id="news" name="news" size="20" style="width:400px; height:370px; border:1px solid #BBBBBB; float:left; overflow:auto">
<?php
foreach($news as $load_news)
{
?>
<option value="<?php echo $load_news["id"]; ?>"><?php echo $load_news["headline"]; ?></option>
<?php }?>
</select>
<td><a href="exec_setpage.php"></a></td>
<?php
require_once('includes/config.php');
if(!isset($_SESSION['Auth']['id']))
{
header("Location: index.php");
exit;
}
$errors = array();
$Admin = new admins;
if(isset($_POST['Add']))
{
$id = $_GET['id'];
$sql = "SELECT id,status FROM news WHERE id=".mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
mysql_query("Update news SET status='1' WHERE id=".mysql_real_escape_string($_GET['id']));
if(mysql_affected_rows() > 0)
{
$_SESSION['message'] = "News Added Successfully";
header("Location:sethomepage.php");
exit;
}
else
$_SESSION['message'] = "News Already Added Top List.";
header("Location:sethomepage.php");
exit;
}
?>
sethomepage.php代码
<form action="exec_setpage.php" name="sel_news" method="post">
<select>
...
</select>
<input type="submit" name="submit">
添加
和
,让魔法发挥作用。。顺便说一句,你必须在POST
和GET
之间进行选择,因为你在第二页中把它完全混淆了。。
<form action="exec_setpage.php" name="sel_news" method="post">
<select id="news" name="news" size="20" style="width:400px; height:370px; border:1px solid BBBBBB; float:left; overflow:auto">
<?php
foreach($news as $load_news)
{
?>
<option value="<?php echo $load_news["id"]; ?>"><?php echo $load_news["headline"]; ?></option>
<?php }?>
</select>
<input type="submit" name="submit">
$id = $_POST['news'];