Page 1 of 1

Delete this.

Posted: Sun Sep 18, 2005 10:36 pm
by Charles256

Code: Select all

function stategen($o,$test)
  {
  ?>
    <option value='
   <?php 
     echo ("$o"); 
   ?>
     '
   <?php 
     if ("$test"=="$o")
     { 
       echo ('selected');
     }
    ?>
	>
    <?php 
      echo ("$o $test");
     ?>
     </option>
    <br />
    <?php
   }
that's the function...
heres the other parts of the code...

Code: Select all

$State=$_POST['State'];
stategen("Alabama","$State");
State is actually defined above the function and obviously the function is called after the function is defined:-D however, even though both test and o will both read, say arkansas it will not put the attribute selected into the option. any ideas?

Posted: Sun Sep 18, 2005 11:18 pm
by Charles256
i know i didn't state it but if it isn't clear enough just let me know, I'll try to explain again.

Posted: Sun Sep 18, 2005 11:18 pm
by wyred
I suggest you write your stategen() this way...

Code: Select all

function stategen($o,$test) {
    $result = "<option value='$o'";
    if ($test==$o) $result .= ' selected';
    $result .=  ">$o $test</option><br />";
    echo $result;
}

Posted: Sun Sep 18, 2005 11:31 pm
by Charles256
that worked.. i don't know what the difference is. i mean, yours is WAY more efficient but the functionality should be the same..thanks

Posted: Sun Sep 18, 2005 11:58 pm
by John Cartwright
I don't think you can break out of PHP mode in functions

Posted: Mon Sep 19, 2005 12:01 am
by Charles256
sure you can. i have a function that works successfully that breaks out of PHP. I'd post hte code but I'm assuming we can just take my word on that;)

Posted: Mon Sep 19, 2005 12:20 am
by John Cartwright
My mistake then :cry:

Posted: Mon Sep 19, 2005 2:31 pm
by ryanlwh
i think it's "$test"=="$o" versus $test==$o.

and i have broken out of php mode in functions (and functions in a class) so many times that I can guarantee it works :)

problems continued...

Posted: Mon Sep 19, 2005 4:36 pm
by Charles256

Code: Select all

foreach ($_POST as $key=>$value)
	  {
	  	if ($key!='Register')
		{
			if ($value=='')
			{
			  $varname="form_" .$key;
			  $$varname="<font color='RED'>Please enter something here.</font>";
			  $Error=1;
			}
		}
	  }
That's the loop... here's the form that's posted, or at least the part that should coincide with $key!='Register'

Code: Select all

<input type="submit" name="Register" value="Register">
and on the other page when it determines when to display the form looks like...

Code: Select all

if ($Error==1 || !(isset($Error)))
	{
	include('form.php');
	}
Now obviously I submitted a blank form but the $Error=1 part didn't get executed because the form isn't displayed after it is submitted. any ideas?