dongyi6543 2016-11-25 06:16
浏览 50

为什么我不能通过PHP中的$ _POST存储选定的值

I create a dropdown list to select values:

 <form action="." method="post" id="aligned">
    <input type="hidden" name="action" value="update_customer">
    <input type="hidden" name="customer_id" 
           value="<?php echo htmlspecialchars($customer['customerID']); ?>"> 


    <label>Country:</label>
    <select name="selected">
     <?php  

        $dbhost = 'localhost';
        $dbuser = 'root';
        $dbpass ='';
        $db = 'tech_support';

        $conn = mysql_connect($dbhost, $dbuser, $dbpass);
        if(!$conn)
            die('Could not connect: '. mysql_error());

        mysql_select_db($db);
        $selected= mysql_query("select * from countries where countryCode = '" .$customer['countryCode']. "'");
        $sql = mysql_query("select * from countries order by countryName");

        if($selectedrow = mysql_fetch_array($selected)){
             echo "<option selected value=\"VALUE\">" . $selectedrow['countryName']."</option>";
        }
         //echo "<select>";

        while ($row = mysql_fetch_array($sql)) {
        echo "<option value =\"VALUE\">". $row['countryName']."</option>";
        }
        //echo "</select>";
       ?> 
    </select><br>

In another php file as below, I was trying to store the selected value for Country, but nothing is stored, why?

<?php $country_name = $_POST["selected"];
echo $country_name;//it always print out 'VALUE'-I guess it means null.
?>
  • 写回答

1条回答 默认 最新

  • dqpc1845 2016-11-25 06:26
    关注

    You should use

    echo "<option value ='".$row['countryName']."'>". $row['countryName']."</option>";
    

    And I want to add something, MySQL is deprecated in PHP5 and removed from PHP7. what is your PHP version. If you use PHP 5 or later use mysqli.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据