On 20 November 2010 23:31, Jason Pruim <lists@xxxxxxxxxxxxxxxxxxxx> wrote: > Hey Everyone! > > So I came across a problem that I don't know how to fix... I have searched > and thought and just not having anything click as to where I am messing > up... > > I have a few functions as follows: > <?PHP > > function ddbYear($name, $message, $_POST, $option){ > > Â Â//Make sure to post form start/stop OUTSIDE of this function... > Â Â//It's not meant to be a one size fits all function! > echo "NAME: " . $name . "<BR>"; > echo "MESSAGE: " . $message . "<BR>"; > > echo "POST: " . $_POST . "<BR>"; > echo "OPTION: " . $option . "<BR>"; > > > $sticky = ''; > if(isset($_POST['submit'])) { > $sticky = $_POST["{$name}"]; > echo "STICKY: " . $sticky; > } > //echo "OPTION: "; > //print_r($option); > > Â Âecho <<<HTML > <select name="{$name}"> > <option value="0">{$message}</option> > > HTML; > > foreach ($option as $key => $value){ > > if($key == $sticky) { > echo '<option value="' . $key .'" selected>' . $value . '</option>'; > }else{ > echo '<option value="' . $key .'">' . $value . '</option>'; > } > > } > > echo <<<HTML > > </select> > HTML; > unset($value); > return; > } > > ?> > > One for Month, Day & Year... All the same exact code... When I get brave > I'll combine it into 1 functions :) > > Now... What it's trying to do.. It's on a "update" form on my website. > Basically pulls the info from the database and displays it in the form again > so it can be edited and resubmitted... > > As I'm sure you can tell from the function it checks to see if the a value > has been selected in the drop down box and if it has then set the drop down > box to that value. > > I call the function like this: > <?PHP > $startYear = date("Y", $row['startdate']); //Actual DBValue: 1265000400 > $optionYear = array("2010" => "2010", "2011" => "2011", "2012" => "2012", > "2013" => "2013", "2014" => "2014"); > > ddbYear("startYear", "Select Year", $startYear, $optionYear); > > > ?> > > The output I'm getting is: > THESE ARE THE ACTUAL UNPROCESSED (OTHER THEN SEPARATING) VALUES FROM THE > DATABASE > startmonth: 2 > startday: 1 > startYear: 2010 > endmonth: 11 > endDay: 30 > endYear: 1999 > > THESE ARE THE VALUES INSIDE THE FUNCTION > NAME: startYear > MESSAGE: Select Year > POST: 2010 > OPTION: Array > STICKY: 2 > > Now... The problem is that $sticky get set to "2" instead of "2010"... But I > can't figure out why... > > Anyone have any ideas? > > And just incase I didn't provide enough info here's a link that shows it > happening: > > HTTP://jason.pruimphotography.com/dev/cms2/events/update_form.php?id=62 > > Thanks for looking and for your answers in advance! :) > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > It is extremely counter-intuitive to have parameters named after superglobal variables. <?php /** * This function looks like it does nothing. */ function EmptyFunction($_POST) { } // Build $_GET $_GET['Name'] = 'Richard'; print_r($_GET); print_r($_POST); EmptyFunction($_GET); print_r($_GET); print_r($_POST); ?> Rather than doing nothing, any parameter passed to it will be assigned to the super global $_POST array. There is no "pass be reference" &$_POST which would be one way to alter a variable that exists outside of the scope of the function. If your intention _IS_ to assign to the $_POST super-global, then just assign it. Don't pass it. Using any super global as a parameter is almost always NOT going to have the intent required. Things get really quite odd if the parameter is $GLOBALS. <?php function EmptyFunction($GLOBALS) { } // Build $_GET $_GET['Name'] = 'Richard'; $Age = 43; EmptyFunction($_GET); var_dump($GLOBALS); echo $Name, $Age; ?> The output here is ... array(1) { ["Name"]=> string(7) "Richard" } Notice: Undefined variable: Name in Z:\testsg.php on line 12 43 So, the link between the global variables and $GLOBALS super global is now broken. $Name isn't in global scope and $Age isn't in $GLOBALS. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php