PHP error thrown in HTML script?

A client registration scirpt has worked since 2007. After working on the parent script the registration section fails on an HTML tag. I cannot figure out why.

Could someone offer a suggestion of how to debug this?
I’ve lifted out a segment where the only two tags occur …

[php]



<TR><TH align=RIGHT> Street Address1: 
	<TD> <input type='text' name = 'address1'     size = '38' maxlength = '1000' /></TD>  
    <TH align=RIGHT> City: 
	<TD> <input type='text' name = 'city'         size = '38' maxlength = '50' /></TD></TR> 


<TR><TH align=RIGHT> Street Address2: 
	<TD> <input type='text' name = 'address2'     size = '38' maxlength = '1000' /></TD>  

    <TH align=RIGHT> State: 
	<TD width='30'>
	[b]<select[/b] name = 'state' size='1' maxlength='6' option selected="<?php echo $state ?>"/>

<?php 
  foreach($b as $k=>$v) {
  	if ($v==$state) 
	  echo "<option value='$k' selected >$v</option>";
	else
	  echo "<option value='$k'>$v</option>";
  			  } 
?>
        </select></TD>

<TR><TH align=RIGHT> Country: 
	<TD width='30'>
	[b]<select[/b] name = 'country' size='1' maxlength='6' option selected="<?php echo $country ?>"/>

<?php 
  foreach($a as $k=>$v) {
  	if ($v==$country) 
	  echo "<option value='$k' selected >$v</option>";
	else
	  echo "<option value='$k'>$v</option>";
  			  } 
?>
        </select></TD>

     <TH align=RIGHT>Zip code:
	<TD> <input type='text' name='zip' size='10' maxlength='12'/></TD>


 <TR><TH align=RIGHT> Email address: 
	<TD> <input type='text' name = 'email' size = '38' maxlength = '40' /></TD> 
First name:
Last name:
Company*:
[/php]

The error thrown are ‘Undefined variable’ as follows

[php] <select name = ‘state’ size=‘1’ maxlength=‘6’ option selected="PHP Notice: Undefined variable: state in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/Tests/TST_form2.php on line 28
"/>

    PHP Notice:  Undefined variable: b in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/Tests/TST_form2.php on line 31

PHP Warning: Invalid argument supplied for foreach() in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/Tests/TST_form2.php on line 31

    <TR><TH align=RIGHT> Country:
            <TD width='30'>
           [b] <select [/b]name = 'country' size='1' maxlength='6' option selected="PHP Notice:  Undefined variable: country in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/Tests/TST_form2.php on line 42

"/>

    PHP Notice:  Undefined variable: a in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/Tests/TST_form2.php on line 45

PHP Warning: Invalid argument supplied for foreach() in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/Tests/TST_form2.php on line 45
[/php]

Note that these errors are thrown even in this snippet that has none of the parent code.
Futhermore, a pre 2007 version fails the same way, but its parent code had not been modified(?)

Any suggestions on how to debut this error would be greatly appreciated.

usit

Well, as the errors suggests, the variables are now undefined. Did you recently upgrade PHP or move servers? You said you modified the “parent script” so why don’t you post that as well?

  1. (My unclear view:) I didn’t post more code because I thought that the supposed ‘undefined variables’ were actually being defined between the associated <select … /select> tags in the enclosed snippet – the purpose of the form.

  2. Yes, I switched from php4 to php5, and have been trying to clean up the ashes.

  3. Is there a source explaining what changes to php4 code are needed to run an old script under php5?

Thanks for considering my problem.
stuck at
usit

Update:
*Have read several discussions of php4-to-php5 transition issues w/o finding any useful clues.

*Have found no conflicts in my script w/ php5 reserved words.

*Have yet to find any discussion of possible HTML interactions w/ php5.

usit

Well I can’t see anywhere in this code where those variables are defined.

The most common problem I’ve seen with PHP4 to PHP5 is the register_globals setting in php.ini. It used to be commonly set to on in PHP4 and has been deprecated and removed in PHP5.3 or greater version.

So, set register_globals = On in your php.ini and see if the code works.

UPdate2:
*I set register_globals = on in ini.php and the program still doesn’t work.

*Where I thought I was setting variables is in this snippet (for example):

[php]

<select name = ‘state’ size=‘1’ maxlength=‘6’ option selected="<?php echo $state ?>"/>

<?php foreach($b as $k=>$v) { if ($v==$state) echo "$v"; else echo "$v"; } ?>
    <[b]/select[/b]></TD>[/php]

Does this have some kind of php5 syntax error, or am I confused about what defining variables is?

Don’t give up on me yet – getting old and learning more slowly. :frowning:
usit

Are you adding these forum codes to try and bold them here? I hope that isn’t in your actual source code

This code is attempting to loop an array called $b

[php]
foreach($b as $k=>$v) {
if ($v==$state)
echo “$v”;
else
echo “$v”;
}
[/php]

I don’t see in any of the code you posted where $b is defined as an array.

Sponsor our Newsletter | Privacy Policy | Terms of Service