PHP 代码,用于从列表框中获取选定的索引 ID 并在另一个页面上获取 ID


php code to get selected index id from listbox and get id on another page

表名 --- 新闻

我创建了两个页面1)设置主页.php2)exec_setpage.php

我创建了一个列表框并从sethomepage上的数据库中填充它.php

现在我需要将所选值的 id 从列表框传递给exec_setpage.php

下面是我的代码

请建议我如何在另一页上获取选定的值索引和 GET。

因为它向我显示错误未定义的索引 ID

设置首页.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>

exec_setpage.php代码

<?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 code

<form action="exec_setpage.php" name="sel_news" method="post">
<select>
...
</select>
<input type="submit" name="submit">

exec_setpage.php

$id = $_POST['sel_news'];        //Get the value of selected option
<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'];