Question

I want to get what option the user selected and the "value" of that <option> to be stored in his account (I have a MySQL register system).

I made the table, everything is alright, username works perfectly, password works perfectly, but I got stuck at the selection part:

<td>team:</td>
<td>
    <select name="teamlist" form="regform">
        <option value="AstraGiu">Astra Giurgiu</option>
        <option value="FCBotosani">FC Botosani</option>
        <option value="FCBrasov">FC Brasov</option>
        <option value="CeahlaulPN">Ceahlaul Piatra Neamt</option>
        <option value="CFRCluj">CFR Cluj</option>
        <option value="DinamoBuc">Dinamo Bucuresti</option>
        <option value="FarulCta">Farul Constanta</option>
        <option value="GazMetanM">Gaz Metan Medias</option>
        <option value="OtelulGal">Otelul Galati</option>
        <option value="PanduriiTgJiu">Pandurii Targu-Jiu</option>
        <option value="PetrolulPlo">Petrolul Ploiesti</option>
        <option value="RapidBuc">Rapid Bucuresti</option>
        <option value="SteauaBuc">Steaua Bucuresti</option>
        <option value="UCluj">Universitatea Cluj</option>
        <option value="UCraiova">Universitatea Craiova</option>
        <option value="UTAArad">UTA Arad</option>
        <option value="FCVaslui">FC Vaslui</option>
    </select>
</td>

After the user enters their username, pass, and selects the team, I have made this button...

<td colspan="2" align="right"><input type="submit" name="submit" value="register"/></td>

And if this helps you, here's how I store it..

<?php
    if (isset($_POST['submit'])) {
        $username = secure('username');
        $password = md5($_POST['password']);
        $team = secure('team');

        if (empty($_POST['username'])) {
            echo "The username field is empty.";
        } else {
            if (empty($_POST['password'])) {
                echo "The password field is empty.";
            } else {
                if (empty($_POST['team'])) {
                    echo "The team field is empty.";
                } else {
                    $query = mysql_query("SELECT * FROM `users` WHERE `username` = '". $username ."'") or die(mysql_error());
                    if(mysql_num_rows($query) == 1){
                        echo "The username already exists.";    
                    } else {
                        $query = mysql_query("INSERT INTO `users` VALUES(NULL, '". $username ."', '". $password ."', '". team ."')") or die(mysql_error());
                        echo "Successfully registered.";
                    }
                }
            }
        }
    }
?>

How do I get what team he selected and store the "value" of that team (option) in the MySQL database?

Was it helpful?

Solution

Have you tried this?

$_POST['teamlist']

I'm assuming your secure function accepts the name of a form element, so you could change this line:

$team = secure('teamlist');

and change this:

if (empty($_POST['teamlist'])) {
    echo "The team field is empty.";
}

Although I see in your validation that you're subscribing to the arrow anti-pattern

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top