Re: PHP not passing array? maybe newbie question...

From: Date: Mon, 31 Jul 2000 23:49:50 +0000
Subject: Re: PHP not passing array? maybe newbie question...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-9313@lists.php.net to get a copy of this message
Peter Torraca wrote: > Hi All -- > > Following a printed example in New Rider's MySQL book, I've > newbie-hacked my way to the following script. Unfortunately, it is > not working and I can't figure out > why. > > Here's the setup: from an php page displaying DB contents and form > blanks, you can insert new values into a field called status. The > status field is associated with a unique identifier, 'id'. > > Here is how the status blank is created: > > $change_stat = sprintf ("<INPUT TYPE=\"text\" > NAME=\"status[%s]\"", > $row["id"]); $change_stat .= sprintf (" VALUE=\"%s\" > DEFAULT=\"%s\" > SIZE=\"5\"><BR>",$row["status"], $row["status"]); I hope this thing is not sending HTML formatted mail. Remove status[%s]. Just use status[]. PHP will parse it for the next page into an array with numeric indexes. I don't believe you can pass associative arrays this way. Example: <INPUT TYPE="hidden" NAME="myarray[]" VALUE="BLAH1"> <INPUT TYPE="hidden" NAME="myarray[]" VALUE="BLAH2"> <INPUT TYPE="hidden" NAME="myarray[]" VALUE="BLAH3"> <INPUT TYPE="hidden" NAME="myarray[]" VALUE="BLAH4"> In the page that receives the data, myarray[0] contains BLAH1, myarray[1] contains BLAH2, etc. Also, I'm not sure why you're using sprintf. There is probably a good reason, but I use simple assignment for most of my code. $myvar = "$i $string" will return "1 blah" if $i is 1 and $string is "blah". > > > I enter the new data and hit the 'submit' button on the html form. > In theory (and according to New Riders), PHP stuffs everything into > an array, here called $status, and passes it to the next sub. > > PHP begins inserting the new data into the DB with using a while/each > line, but goes belly-up after the first bit of data. PHP complains > 'data passed to "each" is not an array or object'. Here is the > insertion code: > > while (list ($id, $nu_status) = each ($status)) { $query = "UPDATE > result SET status=\"$nu_status\" WHERE id = $id"; > if (!mysql_query ($query)) die ("Sorry, data entry failed for id # > $id. Please check your entry"); } > > What is going wrong? It inserts the first row of data without a > hitch, but nothing after... > > Now, I'm sure I botched this someplace, but I can't peg it down. Hope > somebody can help... my third cup coffee didn't. =] > > I'd be happy to give more details if needed. If this is answered > someplace like a FAQ or discussion board, please send me a URL! > > regards, > -pt > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#9313) next »