I am building a form to update multiple records in a database. I go through a do-while loop to make changes to the database but I have echoed the variables just so I can see what is happening. The variables are all showing up right when they are echoed but the last update in the loop always enters 'array' into the database in all fields. WHY is this showing on the screeen properly but not in the database? 😕
if($edit_tour_data=="Edit Tour Data")
{
// get tour rows
$result = mysql_query("SELECT * FROM tour_data WHERE tid LIKE '$tid' order by frame")
or die("Invalid query: " . mysql_error());
if ($data = mysql_fetch_array($result))
{
echo "Editing information for tour ($tid). <table align=center border=0>";
$counter=0;
do
{ // echo data for each row
$row=$data["row"];
echo "<tr><td>$counter: Row $row</td>";
echo "<td>Frame: ($frame[$counter])</td>";
echo "<td>$text[$counter]</td>";
echo "<td>URL: $urlname[$counter] </td>";
echo "<td>$url[$counter]</td>";
echo "<td>Delete: ($delete[$counter])";
// change data
mysql_query ("UPDATE tour_data SET
text='$text[$counter]',
frame='$frame[$counter]',
url='$url[$counter]',
urlname='$urlname[$counter]'
WHERE row=$row
");
// delete row
if($delete[$counter]==delete)
{
mysql_query ("delete from tour_data where row = '$row'");
echo " - Deleted";
}
echo "</td></tr>";
$counter=$counter+1;
}while($data = mysql_fetch_array($result));
echo "</table><hr width=300>";
}
The form is on the same page. It looks like this:
$result2 = mysql_query("SELECT * FROM tour_data WHERE tid LIKE '$tid' order by frame")
or die("Invalid query: " . mysql_error());
if ($data2 = mysql_fetch_array($result2))
{
<form name='form1' method='post' action='tour_edit2.php'>
<table border=0 align=center bordercolor="#009933">
<?
$entry=1;
do
{
$frame=$data2["frame"];
$row=$data2["row"];
$image=$data2["image"];
$url=$data2["url"];
$urlname=$data2["urlname"];
$text=$data2["text"];
$image2 = explode(".", $image);
$filename=$image2[0];
?>
<tr>
<td valign=top><strong>Order
<input type='text' size=6 name='frame[]' value='<? echo $frame; ?>'>
</strong>Row: <? echo $row; ?></td>
<td valign=top><div align="center"><a href='http://wblrd.sk.ca/~digital_sask/images/$image' target=_blank>
<img src='http://wblrd.sk.ca/~digital_sask/images/tn_<? echo $filename; ?>_jpg.jpg' border=0></a>
</div></td>
<td valign=top><b>Add a Link</b> (optional) <br>
Title:
<input type='text' name='urlname[]' value='<? echo $urlname; ?>' size='<? echo $size; ?>'>
<br>
URL:
<input type='text' name='url[]' value='<? echo $url; ?>' size='<? echo $size; ?>'>
</td>
<td> <div align="right">
<input type='checkbox' name='delete[]' value='delete'>
<font size=2 color=red>DELETE</font></div></td>
</tr>
<tr>
<td valign=top><p align="right"><strong>Text:</strong><br>
</p>
<div align="center"></div></td>
<td colspan=3 valign=top>
<textarea name="text[]" cols="55" rows="5"><? if($text!="")
{
echo $text;
}
?></textarea><hr></td>
</tr>
<?
$entry=$entry+1;
}while($data2= mysql_fetch_array($result2));
?>
<?
}
?>
</table>
<div align="center">
<input name="edit_tour_data" type="submit" id="edit_tour_data" value="Edit Tour Data">
</div>
</form>