Getting arrays out of HTTP_POST_VARS
| From: | Ian Evans | Date: | Sat, 27 Oct 2001 19:14:17 +0000 |
| Subject: | Getting arrays out of HTTP_POST_VARS | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-72578@lists.php.net to get a copy of this message | ||
My mind is going blank here and I feel like I'm missing something basic.
I have an insert form for movie profiles that takes cast members, writers and directors and inserts
them into the
tables for the correct movieid.
In the old version of the script I would repeat the inserting section of the code three times, once
for casts,
once for directors and once for writers. The script checks if the person's first/middle/last
name exists in the
people table. If it does it grabs the id number, if it doesn't it doesn't it inserts it
and gets the id number.
The peopleid and titleid are then inserted into the appropriate table. (casts, writers, directors)
I decided to streamline the code with a function so that calling peopleinserter($table,$titleid)
would loop
through the form variables and insert into the appropriate table. I can easily grab the results of
the
$HTTP_POST_VARS but I'm going blank trying to get the array out of the array.
Here's a snippet:
function peopleinserter ($table,$titleid) {
//$titleid = the titleid from the titles table
//$table = the job table e.g. casts, directors, writers
global $HTTP_POST_VARS;
$firstvar = "first$table"; //if $table = casts it would grab the firstcasts variables from
the form
$middlevar = "middle$table";
$lastvar = "last$table";
while (list ($key, $val) = each ($HTTP_POST_VARS[$lastvar])) {
//in this example $lastvar=lastcasts, so it's calling each ($HTTP_POST_VARS[lastcasts])
// if I echo $key $val for this I would get for example "0 Thornton 1 Jolie
//end snippet
How do I call the key of the firstcasts, middlecasts, lastcasts arrays so I can do stuff like:
$lastcasts[$key] = trim($lastcasts[$key]); and
$sql = "SELECT peopleid, first, middle, last FROM people WHERE
first='$firstcasts[$key]' and middle='$middlecasts[$key]' AND
last='$lastcasts[$key]]'";
In other words, how do I get those three arrays out of the HTTP_POST_VARS array?
Banging head on desk...