Delete this.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Delete this.

Post 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?
Last edited by Charles256 on Tue Sep 20, 2005 11:37 am, edited 1 time in total.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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.
wyred
Forum Commoner
Posts: 86
Joined: Mon Dec 20, 2004 1:59 am
Location: Singapore

Post 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;
}
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I don't think you can break out of PHP mode in functions
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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;)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

My mistake then :cry:
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post 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 :)
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

problems continued...

Post 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?
Post Reply