Jump to content

Updating mysql


vicodin

Recommended Posts

Ok i need to update 5 things in mysql all at the same time. The table is in this format:

------------------------ 
ID | Event | Link | Date |
------------------------
1 |    x    |   x   |   x    |
2 |    x    |   x   |   x    |
3 |    x    |   x   |   x    |
4 |    x    |   x   |   x    |
5 |    x    |   x   |   x    |
-------------------------

I have 5 in dividual input boxes they can submit, and they are all being inputted into an array so i have $event[] , $link[] , $date[].

I cant figure out how to take the arrays and have them update the db... Any help would be greatly appreciated...Thanks!

Link to comment
https://forums.phpfreaks.com/topic/117915-updating-mysql/
Share on other sites

I have this echoing 5 times so there is 5 rows of it.

echo "<tr>";
echo '<td class="event"><input type="text" name="enum[]" value="'.$row['num'].'" maxsize="1" size="5"></td>';
echo '<td class="event"><input type="text" name="event[]" value="'.$row['event'].'" size="25"></td>';
echo '<td class="event"><input type="text" name="elink[]" value="'.$row['link'].'" size="25"></td>';
echo '<td class="event"><input type="text" name="edate[]" value="'.$row['date'].'" size="10"></td>';
echo "</tr>";
echo "<tr>";
echo '<td class="event"><input type="text" name="enum[]" value="'.$row['num'].'" maxsize="1" size="5"></td>';
echo '<td class="event"><input type="text" name="event[]" value="'.$row['event'].'" size="25"></td>';
echo '<td class="event"><input type="text" name="elink[]" value="'.$row['link'].'" size="25"></td>';
echo '<td class="event"><input type="text" name="edate[]" value="'.$row['date'].'" size="10"></td>';
echo "</tr>";
echo "<tr>";
echo '<td class="event"><input type="text" name="enum[]" value="'.$row['num'].'" maxsize="1" size="5"></td>';
echo '<td class="event"><input type="text" name="event[]" value="'.$row['event'].'" size="25"></td>';
echo '<td class="event"><input type="text" name="elink[]" value="'.$row['link'].'" size="25"></td>';
echo '<td class="event"><input type="text" name="edate[]" value="'.$row['date'].'" size="10"></td>';
echo "</tr>";
echo "<tr>";
echo '<td class="event"><input type="text" name="enum[]" value="'.$row['num'].'" maxsize="1" size="5"></td>';
echo '<td class="event"><input type="text" name="event[]" value="'.$row['event'].'" size="25"></td>';
echo '<td class="event"><input type="text" name="elink[]" value="'.$row['link'].'" size="25"></td>';
echo '<td class="event"><input type="text" name="edate[]" value="'.$row['date'].'" size="10"></td>';
echo "</tr>";
echo "<tr>";
echo '<td class="event"><input type="text" name="enum[]" value="'.$row['num'].'" maxsize="1" size="5"></td>';
echo '<td class="event"><input type="text" name="event[]" value="'.$row['event'].'" size="25"></td>';
echo '<td class="event"><input type="text" name="elink[]" value="'.$row['link'].'" size="25"></td>';
echo '<td class="event"><input type="text" name="edate[]" value="'.$row['date'].'" size="10"></td>';
echo "</tr>";

 

That brings up another question... i dont even know if that will post as an array will it?

 

Link to comment
https://forums.phpfreaks.com/topic/117915-updating-mysql/#findComment-606529
Share on other sites

Your description is a little ambiguous, especially since you didn't mention having the ids in an array, but I'll assume you just forgot to mention that...

 

Try something like this...

 

<?php
for($i = 0; $i < count($id); ++$i)
{
  // Put in your own code to clean the arrays to make sure people aren't sql injecting

  $query = "UPDATE table SET Event = '{$event[$i]}', Link = '{$link[$i]}', Date = '{$date[$i]}' WHERE ID = {$id[$i]}";

  // Put in your own query implementation here
}
?>

 

Of course that isn't copy/paste code, but maybe something to give you a general idea of what you need to do.

Link to comment
https://forums.phpfreaks.com/topic/117915-updating-mysql/#findComment-606530
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.