0

I retrieve multiple rows from one table and I display them in a grid. For each row I want to be able to change the name and then make one update that updates every row. the grid looks something like this: ...

while ($rowsf=mysql_fetch_assoc($getrows)) {
$namelist=$rowsf['name'];
echo '<input name="nameupdate" type="text" value="'.htmlspecialchars($namelist, ENT_QUOTES).'"/><br>';
}

I currently have the following code, which would work if I had an array. Is it possible to save each $nameupdate in an array?

 $nameupdate = $_POST['nameupdate'];
    $updateall=$_POST['updateall'];
        if ($updateall) {
        for($i=0; $i<=$maxpos; $i++) {
        mysql_query("update table set name='$nameupdate[$i]' where playlistid=$playlistget and pos=$i");
        }
        header("Location: mysite.php");
        }

What would be the best way to update the rows?

1 Answer 1

1

To submit HTML data as an array to post.

echo '<input name="nameupdate[]" type="text" value="'.htmlspecialchars($namelist,     ENT_QUOTES).'"/><br>';

Then in the php side

$nameupdate = $_POST['nameupdate'];
foreach ($nameupdate as $name)
{
   // Update the Value
}
Sign up to request clarification or add additional context in comments.

1 Comment

I want an array that has all $nameupdate values in it. Is this really all you have to do?

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.