开发者

How do I select value from DropDown list in PHP??? Problem

开发者 https://www.devze.com 2022-12-27 00:28 出处:网络
I want to know the error in this code The following code retrieves the names of the mem开发者_JAVA技巧bers of the database query in the

I want to know the error in this code

The following code retrieves the names of the mem开发者_JAVA技巧bers of the database query in the dropdownlist

But how do I know who you selected.... I want to send messages only to the members that selected form dropdown list

    <?php
include ("connect.php");



    $name = $_POST['sector_list'];

    echo   $name  ;

?>


    <form method="POST" action="" > 
    <input type="hidden" name="sector" value="sector_list"> 
    <select name="sector_list" class="inputstandard"> 
    <option  size ="40" value="default">send to </option> 

    <?php 
        $result = mysql_query('select  * from  members  ')  
        or die (mysql_error());  

        while ($row = mysql_fetch_assoc($result)) { 

            echo '<option size ="40" value=" '. $row['MemberID'] . '" name="' . $row['MemberName']. '">' . $row['MemberName']. '</option>'; 

       } 

    ?> 

    </select> 
    </form>

I hope somebody can help me


This should do the trick.

<?php
$member_id = intval($_POST['sector_list']);

if($member_id == 0) {
    // Default choice was selected
}
else {
    $res = mysql_query("SELECT * FROM members WHERE MemberID = $member_id LIMIT 1");
    if(mysql_num_rows($res) == 0) {
        // Not a valid member
    }
    else {
        // The member is in the database
    }
}
?>

<form method="post" action="">
    <input type="hidden" name="sector" value="sector_list"> 
    <select name="sector_list" class="inputstandard"> 
        <option value="0">send to</option>
        <?php 
        $result = mysql_query('SELECT * from members') or die(mysql_error());  

        while ($row = mysql_fetch_assoc($result)) {
            echo '<option value="' . $row['MemberID'] . '">' . $row['MemberName']. '</option>'; 
        }
        ?> 
    </select>
</form>

To get an input to change when you select someone try this:

<select onchange="document.getElementById('text-input').value = this.value;">
<!-- Options here -->
</select>
<input type="text" id="text-input">
0

精彩评论

暂无评论...
验证码 换一张
取 消