html - Looping through post count php

echo "<form method='POST' action=''>";
if( $row=mysql_fetch_array($result)){

while( $row=mysql_fetch_array($result))
echo "<tr>
    <td> "?><input type="hidden" id="id" name="id[]" value=" <?php echo $row['id']?>"> <input id="txt_port" name="txt_port[]" type="text" class="required" title="Port. This is a required field" value=" <?php echo $row['Destination_port'] ?> "></td> 
    echo "<td><a onclick='return show_confirm();'><input name='update[]' class='button' type='submit' value='Update'></input></a></td></tr>";

    if(ISSET($_POST["update"]) and $_SERVER['REQUEST_METHOD'] == "POST"){   

    echo $id[$counter];
    echo $port[$counter];

    $result=mysql_query("UPDATE protocols SET Destination_port=".$port[$counter]." WHERE id=".$id[$counter].";");

   // header("Location: Overview.php?Menu=".$menu."&Overview=1");
echo "</form>";

I made a simple table which as got 3 columns, the first column is a name, second one has a textbox which contains a number (with a hidden id that I need) and last one is a button to update that specific row.

The big problem is when I echo $id[$counter] and echo $port[counter] this stupid counter never counts up. I always end up with the same data! In total it loops 4 times but it gives me the data of the first record.

Any ideas please help.




Can you please show your whole code? I see you have $result variable but I didnt see when you built the sql. In additional, it is highly recommend that you use mysqli or PDO as mysql_ are deprecating.

People are also looking for solutions to the problem: package - Move PHP binaries to another server


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.