简体   繁体   中英

How to get the selected dropdown item(ID table row) PHP MYSQL

I know have a dropdown menu what shows a items from my MYSQL table. Now it shows these different names but how can i get the selected item in my code.

So if i open the dropdown and i get for example item3 i can do something with this. I want something like if Item 3 is selected -vs- item 4 and fill in form1 is higher(>) than fill in form2. Item 3 gets added 3 points en item 4 0 points.

Hope you can help.

This is the code where the dropdown menu is:

<select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select>
                <input style="width:20px; text-align:center;" type="text" name="hometeam" placeholder="0" />
                -
                <input style="width:20px; text-align:center;" type="text" name="awayteam" placeholder="0" />
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select><br>
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select>

And this is my whole admin.php

<?php
    error_reporting(E_ALL ^ E_NOTICE);

    if(!isset($_COOKIE['E2ingelogd'])) {
        header("location:../../index.php");
    }

    $username = "root";
    $password = "";
    $hostname = "localhost";

    $dbhandle = mysql_connect($hostname, $username, $password) or die("Kan niet inloggen");

    $selected = mysql_select_db("login", $dbhandle);





        if(isset($_POST['team'])){
            $team = $_POST['team'];
            $ID = $_POST['id'];         

            $query = mysql_query("SELECT * FROM e2teams WHERE Team='$team' and ID='$ID'");
            if(mysql_num_rows($query) > 0 ) { //check if there is already an entry for that username
                echo "$team bestaat al!";
            }

            if (!$_POST['team'] ) 
            {
                echo('Foutmelding: Je bent vergeten een <b>team</b> in te vullen');
            }
            else{
                mysql_query("INSERT INTO e2teams (Team) VALUES ('$team')");
                header("location:e2admin.php");
            }
    }

    mysql_close();
?>

<html><head>
<link href='http://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<link href="../css/layout.css" rel="stylesheet" type="text/css"></head>
    <body>
    <div class="wrapper">
            <div class="header">
                <div class="logo"><img height="140" src="../images/boyslogo.png"> </div>
                <div class="titelpagina">Vroomshoopse Boys E2 admin panel</div>
                <div class="uitloggen"><a href="../../logout.php">Uitloggen</a></div>
            </div>
      <div class="content">
                <div class="teamstoevoegenvak">
                    <div class="titelbalk">
                        <h1>Voeg teams toe</h1><br>

                            <form style="border:0px; width:400px; margin:0px; padding:0px;" action="e2admin.php" method="POST">
                                <input style="width=:100%;" type="text" name="team" placeholder="Team naam" /><br>
                                <input type="submit" value="Toevoegen" />
                            </form>
                    </div>
                 </div>
                    <div clas="toegevoegdeteamsvak">
                        <div class="titelbalktoege">
                            <h1>Toegevoegde teams</h1>
                        </div>
                        <div class="deteams">
                            <?php
                                $table = "e2teams";
                                $sql = "SELECT * FROM e2teams";
                                $result = mysql_query($sql, $dbhandle);
                                if(mysql_num_rows($result) > 0){
                                    $team = array();
                                    while($row = mysql_fetch_array($result)) {

                                        echo "<table><tr><td class='styled-td'>";
                                        echo $row['Team']. '</td><td></td><td width="50"><a href="edit.php?edit='.$row['ID'].'">Bewerk</a></td><td><a href="delete.php?del='.$row['ID'].'">Verwijder</a><br>';
                                        echo "</td></tr></table>";
                                        $team = $row['Team'];
                                    }
                                }
                                mysql_data_seek($result, 0);
                            ?>
                        </div>
                </div>  

        <div class="titelbalkuitslagen">
            <h1>Uitslagen</h1>
        </div>
        <div class="volgendewedstrijdvak"> 
            <form action="" method="post">
             <input style="width:410px;" type="text" name="date" placeholder="Datum" /><br>
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>

                </select>
                <input style="width:20px; text-align:center;" type="text" name="thuisteam" placeholder="0" />
                -
                <input style="width:20px; text-align:center;" type="text" name="uitteam" placeholder="0" />
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select><br>
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select>
                <input style="width:20px; text-align:center;" type="text" name="hometeam" placeholder="0" />
                -
                <input style="width:20px; text-align:center;" type="text" name="awayteam" placeholder="0" />
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select><br>
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select>
                <input style="width:20px; text-align:center;"  type="text" name="thuisteam" placeholder="0" />
                -
                <input style="width:20px; text-align:center;" type="text" name="uitteam" placeholder="0" />
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select><br>
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select>
                <input style="width:20px; text-align:center;" type="text" name="thuisteam" placeholder="0" />
                -
                <input style="width:20px; text-align:center;" type="text" name="uitteam" placeholder="0" />
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select><br>
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select>
                <input style="width:20px; text-align:center;" type="text" name="thuisteam" placeholder="0" />
                -
                <input style="width:20px; text-align:center;" type="text" name="uitteam" placeholder="0" />
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select><br>
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select>
                <input style="width:20px; text-align:center;" type="text" name="thuisteam" placeholder="0" />
                -
                <input style="width:20px; text-align:center;" type="text" name="uitteam" placeholder="0" />
                <select name="dropdown">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select><br>
                <input style="margin-left:330px;" type="submit" value="Toevoegen" />
            </form>         
       </div>
       </div>
</div>

    </body>
</html>

You need to put something in the value="" part of the <option that is all that is returned in $_POST or $_GET.

You can put anything in there, normally its the ID of the row that holds the ['Team'] name but it can be anything so for example:

if(mysql_num_rows($result) > 0){
    while($row = mysql_fetch_array($result)) {
        echo '<option value="' . $row['ID'] . '">' . $row['Team'] . '</option>';
    }
}

Or

if(mysql_num_rows($result) > 0){
    while($row = mysql_fetch_array($result)) {
        echo '<option value="' . $row['Team'] . '">' . $row['Team'] . '</option>';
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM