0

Good morning everybody I made a table in html that contains users and the select box contains profiles. I want to assign every users profile in database according to the profile selected in html. My table in html contains checkbox next to every user. I want every user that is checked to be assigned.

        <form action="PHP/modifier.php" method="POSt">
            <table>
            <thead>
                <tr>
                    <th><input type="checkbox" id="checker" name="all"></th> 
                    <th>Username</th> 
                    <th>Nom</th>           
                    <th>Prenom</th>

                </tr>    
            </thead>
                    <?php
            $query="SELECT Username,Nom,Prenom from user";                
                                    $result = mysql_query($query);
                                    $num = mysql_num_rows($result);  
                                for ($i = 0; $i < $num; $i++){
                                   $row =mysql_fetch_array($result);
                                    $Username = $row['Username'];
                                    $Nom = $row['Nom'];
                                    $Prenom = $row['Prenom'];

                echo "<tr id='row'>";
                echo "<td><input type='checkbox' id='check' name='check'".$Username."></td>";
                echo"<td>".$Username."</td>";
                echo "<td>".$Nom."</td>";
                echo "<td>".$Prenom."</td>";
                echo "<td><div id='MAJ'>";

                    echo "</div></td>";
                echo "</tr>";
            }
        ?>
        <h2>Selectionner l'utilisateur et le profile</h2>
        <select name="profile" id="profilez" required>
        <option>Injecteur</option>
        <option>Utilisateur</option>
        <option>Administrateur</option>
        <option>Utilisateur superieur</option>

        <input  type="submit" value="Associer">
        </form>

In the modifer.php I want to make update function to update users but how to get information from checked cases in the html table?

I already wrote this

 <?php
        include "functions.php";
        $profile=$_POST['profile'];
        $Username=$_POST['Username'];
        $query="UPDATE user SET profile = '$profile' WHERE Username = '$Username' " ;
    ?>

I don't know how to do it. thank you so much and sorry for my bad english.

B001ᛦ
  • 2,036
  • 6
  • 23
  • 31
Aeyden
  • 1
  • 1
  • far as I can see, you're not executing your query for `$query="UPDATE user SET profile = '$profile' WHERE Username = '$Username' " ;` – Funk Forty Niner May 11 '15 at 16:29
  • still didn't anything yet i want how to get the checked values from the table i made that's my question – Aeyden May 11 '15 at 16:31
  • *"still didn't do anything"* - doesn't help us much. Here: Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner May 11 '15 at 16:35
  • Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and consider using PDO, [it's not as hard as you think](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 11 '15 at 16:47
  • *They don't give a flying hoot about security Sam*. They just wants dah code man, dah code - @JayBlanchard – Funk Forty Niner May 11 '15 at 17:31

1 Answers1

0

there are different ways to do it. but lets go with your way

on you modifer.php page make another query to get all user names

$row =mysql_fetch_array($result);
foreach ($row as $value)
{
    if (isset($_POST['check'.$value['username']])) 
    {
        $profile = $_POST['profile'];
        $Username = $POST['check'.$value['username'];
        $query="UPDATE user SET profile = '$profile' WHERE Username = $value['username'] " ;
    }
}
Harry
  • 44
  • 6