Arrays/forms/Loops/Persist (was Re: [PHP] UPDATE syntax)
| From: | Gerard Samuel | Date: | Tue, 14 Aug 2001 19:40:48 +0000 |
| Subject: | Arrays/forms/Loops/Persist (was Re: [PHP] UPDATE syntax) | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-62694@lists.php.net to get a copy of this message | ||
Ok, I found out why the UPDATE on the table wasn't working. I wasn't
giving
the command a 'fake' value for the ID column. Ok here is the senario.
I have a form which dumps data to cols 1,2,3,5 in a table (thats
good). I have another script which runs a loop on the data into another
form where I have a textarea, and a checkbox which fills in col 4 and
modifies col 5. What I need to do is when the new form submits, to pass
the textarea, checkbox & ID so I could issue a proper UPDATE. Im able
to get it to echo the textarea & the checkbox, but no luck with the ID.
When the new form is displayed I have the loop echo the ID, but I cant
figure out how to submit the ID array.
// Snip of problem area (Hope it doesn't look sloppy in the message)//
echo "<form action=\"$PHP_SELF?op=reply\" method=\"POST\"
enctype=\"multipart/form-data\">\n";
$c = 0;
while($query_data = mysql_fetch_row($result)) {
echo "<table width=\"100%\" cellspacing=\"2\" border=\"1\"
cellpadding=\"2\" BGCOLOR=\"CCCCCC\"><tr><td width=\"50%\"
valign=\"top\">\n";echo "Database ID: $query_data[0]<br>\n";
echo "Name: $query_data[1]<br><br>\n";
echo "Question:<br> $query_data[2]\n";
echo "<hr>\n";
echo "Post Reply => Yes <input name=\"post[$c]\" type=\"radio\"
value=\"yes\">\n";
echo "No <input name=\"post[$c]\" type=\"radio\" value=\"no\"
checked>\n";
echo "</td><td width=\"50%\" align=\"\">\n";
echo "Reply:<br><textarea rows=\"4\" cols=\"50\" wrap=\"hard\"
name =\"Reply[]\"></textarea>\n";echo "</td></tr></table>\n";
echo "<br><hr><br>\n";
$c = $c + 1;
}
echo "<input type=\"submit\" value=\"Submit\">\n";
echo "</form>\n";// End Snip // I tried creating a new array at the bottom of the loop like so ==> $id[]="$query_data[0]"; and using a hidden field, but that failed. My problem is basically, how does one one make an array 'persist'. I looked through the archive, and didnt find anything substantial. If you need more info please email me. Thanks for listening.... Gerard Samuel wrote:
Thanks for telling me that I was talking jibberish :) OK it worked, but now I have to figure out why its only updating the first row..... Ill be back if I cant figure it out. Thanks all Tyler Longren wrote:yeah...jibberish. Should be this: UPDATE mpn_asklee SET reply='$Reply[$i]', Post='$post[$i]' WHERE ID='$counts'" On Mon, 13 Aug 2001 15:20:17 -0400 Gerard Samuel <trini0@optonline.net> wrote:I have a database with 5 columns and cols 1,2,3 & 5 are filled. I want to insert into 4 and change 5. Could I use an UPDATE command to do this.. Here is what I have ==> $query = "UPDATE mpn_asklee (Reply, Post) VALUES('$Reply[$i]', '$post[$i]') WHERE ID = '$counts'";$result = mysql_query($query); If Im talking jibberish, let me know..