1

I have multiple checkboxes that I need to display, but my code only shows the last checked.

Why is this happening?

below is my code:

<html>
<head>
    <title>CHECK</title>
</head>
<body>
    <?php
    ini_set("display_errors","off");
    if(isset($_POST['vil']))
    {
        $t=$_POST['vil'];
    }
    Else
    {
        $t="";
    }
    ?>

    <form method="post" id="monform" action="">
        <table border=1 width=800  cellpadding=0 cellspacing=1>
            <tr align=center>
                <td>
                    Case
                </td>
                <td>
                    Code
                </td>
                <td>
                    Nom
                </td>
            </tr>
            <?php

            ini_set("display_errors","off");

            $con = @mysql_connect("localhost","root","");
            if(!$con)
            {
                echo "erreur de connexion";
            }
            Else
            {
                mysql_select_db("database",$con);

                $sql = "SELECT * FROM table";
                $result = mysql_query($sql);

                while ($tab=mysql_fetch_array($result))
                {
                    $a=$tab["code"];
                    $b=$tab["nom"];

                    echo "                                       "
                    <tr align=center>
                    <td>
                    <input type=checkbox name=vil[] value=$a>$a<br>
                    </td>
                    <td>
                    $a
                    </td>
                    <td>
                    $b
                    </td>
                    </tr>
                    ";
                }

                ?>
                </table>

                <br><br><input type="submit" name="valider" value="valider">


                <table border=1 width=800  cellpadding=0 cellspacing=1>
                <br><br><?php
                foreach ($t as $variablename)
                {
                    $sql = "SELECT * FROM table WHERE code='".$variablename."'";
                    $result = mysql_query($sql);
                }
                while ($tab=mysql_fetch_array($result))
                {
                    $a=$tab["code"];
                    $b=$tab["nom"];
                    {
                        for ($i=0;$i<count($t);$i++)
                        {
                            echo $a."__".$b."</br>" ;

                            if(isset($t))
                            {
                                echo "                               "
                                <td>
                                $a
                                </td>
                                <td>
                                $b
                                </td>
                                ";
                            }
                        }
                    }
                }
            }


            ?>
        </table>
    </form>
</body>
</html>
Don't Panic
  • 41,125
  • 10
  • 61
  • 80
  • the mysql functions where depreciated years ago, why are you still using them? – Mark Twigg Aug 16 '16 at 15:51
  • 4
    @MarkTwigg They were 'deprecated'. It's unclear what impact this had on their monetary value. – Strawberry Aug 16 '16 at 15:53
  • 1
    @MarkTwigg A better argument is that [mysql_ functions have been removed from PHP](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) ;) Just helping you refine the message. Welcome to the `Stop using mysql_ functions` squad – Machavity Aug 16 '16 at 15:57
  • @Strawberry Listing the 'montery reasons' in a comment is not really practical but to sum, its not actively developed, doesn't support asynchronous queries, doesn't have any OO interface, doesn't have Stored procedures, doesn't have any prepared statements, doesn't have Transactions, doesn't have parameterized queries. I could go on but I think theres enough monetary value in the above list. There is simply no logical reason in my mind why to still be using it, hence asking his what his decision behind this was – Mark Twigg Aug 16 '16 at 15:58
  • 2
    @MarkTwigg He's making a joke. `depreciate` is a monetary term, meaning it lost value. `deprecate` is a term that means to "express disapproval" (i.e. self-*deprecating* humor). The term you want is the latter – Machavity Aug 16 '16 at 16:00

0 Answers0