0

I have made a while loop which displays all users in Ploegen from the database I made it output the text which is suppose to be hidden but im testing it a the moment. anyway it has to update only 1 row the text and id it displays on the page are correct but the update is always ID 1 while i change the option value alot and the valueid (name) always the same.

I have no idea how to make this work I tried as u see, hope u could explain.

I dont need feedback because the code aint good just need help with the issue.

<div class="content-module-main">
                        <?php if(isset($_POST['submit'])){
                        $idtje = $_POST['valueid'];
                        $valueid = $_POST['ploeg'];
                        $idtje = mysqli_real_escape_string($connect, $idtje);
                        $valueid = mysqli_real_escape_string($connect, $valueid);
    //$go = "UPDATE `ploegen` SET `ploeg`='$id' where `id`='$valueid'";
    //$go2 = mysqli_query($connect, $go);
                        echo "<di" . "v class=\"confirmation-box round\">Ploegentest var_dump($valueid); var_dump($idtje);</div>";
                        }
                        ?>
                        <table>
                            <thead>
                                <tr>
                                    <th>Ploeg</th>
                                    <th>Naam</th>
                                    <th>Tel</th>
                                    <th>Gas of Elektra</th>
                                    <th>Wijzig</th>
                                </tr>

                            </thead>
                            <tbody>

                                <tr>
                                    <form method="post" action="home_ploegen_b.php">
                                    <?php 
                                    $query = "SELECT naam, telefoonnummer, id, ploeg, gasofelektra FROM ploegen ORDER by naam DESC LIMIT 100";
                                    if ($result = mysqli_query($connect, $query)) {
                                    while ($get = mysqli_fetch_assoc($result)) {
                                    echo"<tr><td><center>" . $get['ploeg'] . "</center></td>";
                                    echo"<td>" . $get['naam'] . "</td>";
                                    echo"<td>" . $get['telefoonnummer'] . "</td>";
                                    echo"<td>" . $get['gasofelektra'] . "</td>";
                                    echo"<td><center><input type=\"text\" name=\"valueid\" value=\"" . $get['naam'] . "\" /><select name=\"ploeg\">
                                    <option value=\"1\">Ploeg 1</option>
                                    <option value=\"2\">Ploeg 2</option>
                                    <option value=\"3\">Ploeg 3</option>
                                    <option value=\"4\">Ploeg 4</option>
                                    <option value=\"5\">Ploeg 5</option>
                                    <option value=\"6\">Ploeg 6</option>
                                    <option value=\"7\">Ploeg 7</option>
                                    <option value=\"8\">Ploeg 8</option>
                                    <option value=\"9\">Ploeg 9</option>
                                    <option value=\"10\">Ploeg 10</option>
                                    </select><input type=\"submit\" name=\"submit\" value=\"UPDATE\"></center></td></tr>";

                                                                          }
                                    }
                                        ?>                  </td></form>

http://oi42.tinypic.com/2pqrogm.jpg

6
  • your table structure is wrong. check it first and clear it. Commented Jul 5, 2013 at 6:01
  • use separate form for each row. Commented Jul 5, 2013 at 6:18
  • @monojit How would I do that ? lol Commented Jul 5, 2013 at 6:20
  • like your submit button.Implement the form within a loop and pass form id or name. Commented Jul 5, 2013 at 6:23
  • @monojitThanks, make an answer Ill rep u up it worked cant believe I could be so stupid :) Commented Jul 5, 2013 at 6:24

2 Answers 2

1

I think here is the problem you have.

<input type=\"text\" name=\"valueid\" value=\"" . $get['naam'] . "\" />
<select name=\"ploeg\". 

your textfield and select field name is same in all the row. Please put a dynamic name to each field or use name as an array

Reference Links:-

Array Name

Dynamic Naming

Here is your code using array naming

while ($get = mysqli_fetch_assoc($result)) {
    echo"<tr><td><center>" . $get['ploeg'] . "</center></td>";
    echo"<td>" . $get['naam'] . "</td>";
    echo"<td>" . $get['telefoonnummer'] . "</td>";
    echo"<td>" . $get['gasofelektra'] . "</td>";
    echo"<td><center><input type=\"text\" name=\"valueid[]\" value=\"" . $get['naam'] . "\" />
    <select name=\"ploeg[]\">
    <option value=\"1\">Ploeg 1</option>
    <option value=\"2\">Ploeg 2</option>
    <option value=\"3\">Ploeg 3</option>
    <option value=\"4\">Ploeg 4</option>
    <option value=\"5\">Ploeg 5</option>
    <option value=\"6\">Ploeg 6</option>
    <option value=\"7\">Ploeg 7</option>
    <option value=\"8\">Ploeg 8</option>
    <option value=\"9\">Ploeg 9</option>
    <option value=\"10\">Ploeg 10</option>
    </select>
    <input type=\"submit\" name=\"submit\" value=\"UPDATE\"></center></td></tr>";
}

And this one is for dynamic naming

$row = 1;
while ($get = mysqli_fetch_assoc($result)) {
    echo"<tr><td><center>" . $get['ploeg'] . "</center></td>";
    echo"<td>" . $get['naam'] . "</td>";
    echo"<td>" . $get['telefoonnummer'] . "</td>";
    echo"<td>" . $get['gasofelektra'] . "</td>";
    echo"<td><center><input type=\"text\" name=\"valueid$row\" value=\"" . $get['naam'] . "\" />
    <select name=\"ploeg$row\">
    <option value=\"1\">Ploeg 1</option>
    <option value=\"2\">Ploeg 2</option>
    <option value=\"3\">Ploeg 3</option>
    <option value=\"4\">Ploeg 4</option>
    <option value=\"5\">Ploeg 5</option>
    <option value=\"6\">Ploeg 6</option>
    <option value=\"7\">Ploeg 7</option>
    <option value=\"8\">Ploeg 8</option>
    <option value=\"9\">Ploeg 9</option>
    <option value=\"10\">Ploeg 10</option>
    </select>
    <input type=\"submit\" name=\"submit\" value=\"UPDATE\"></center></td></tr>";
    $row ++;
}
Sign up to request clarification or add additional context in comments.

2 Comments

How would you suggest that?
Since you took so much time answering, I liked the answer everything works not thanks!
1

mysqli_fetch_assoc :- Returns an associative array of strings representing the fetched row in the result set, where each key in the array represents the name of one of the result set's columns or NULL if there are no more rows in resultset.

To access the other column(s) of the same name, you either need to access the result with numeric indices by using mysqli_fetch_row() or add alias names.

4 Comments

Uhh? it displays everything correctly lol I just need it at the post it doesnt give the information through properly.
Duh I put an image to clarify what I want when pressing update I want the row I select updated
Yes it's better to understand
Can you help me? when press update I want the row with the if(isset($_POST[submit] to be update but the output ploeg 1 is always 1 and name is always same

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.