Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Issue with php / HTML

See following code:
		<div class="row">
			<div class="col-sm-3 col-xs-3"><div style="padding-left:5px;"><? if ($size == "" && $emsg != "") { ?><span style="color:red;">*&nbsp;</span><? } ?><u>Select Brand/Model</u></div></div>
			<div class="col-sm-3 col-xs-3"><? if ($filttype == "") { ?><input type="text" name = "ctbrand" disabled="true"><? } else { ?>
				<select name="ctbrand" onChange="get_mods();">
					<option value="">-- Select Brand --</option>
					<option value="BAC" <? if ($ctbrand == "BAC") { ?>selected<? } ?>>BAC</option>
					<option value="EVAPCO" <? if ($ctbrand == "EVAPCO") { ?>selected<? } ?>>EVAPCO</option>
					<option value="SPX/MARLEY" <? if ($ctbrand == "SPX/MARLEY") { ?>selected<? } ?>>SPX/MARLEY</option>
					<option value="Other" <? if ($ctbrand == "Other") { ?>selected<? } ?>>Other</option>
				</select>
			<? } ?>	
			</div>
			<div class="col-sm-1 col-xs-1">&nbsp;</div>
<? echo "filttype = " . $filttype . "<br>"; 
 echo "ctbrand = " . $ctbrand . "<br>"; ?>
			<div class="col-sm-3 col-xs-3"><? if ($filttype == "") { ?><input type="text" name = "ctmodel" disabled="true"><? } else { ?>
				<select name="ctmodel" id="ctmodel" onChange="get_dims();">
		<option value="">-- Select Model --</option>
<? // if $_SESSION['ctmodel'] is not null, fill array and select the prior one
		 if ($ctbrand != "") {
			echo "have session ctbrnd = " . $ctbrand . "<br>";
			echo "ns = " . $ns . "<br>";
			for ($i = 0; $i < $ns; $i++) {	
				$ctmod = mysqli_fetch_array($ress,MYSQLI_ASSOC); 
				if ($ctmod['Brand'] == $_SESSION['ctbrand']) {
					$lmodel = $ctmod['Model']; ?>
					<option value="<?print $lmodel; ?>" <? if ($lmodel == $ctmodel) { ?>selected<? } ?>><?print $lmodel; ?></option>
				<? } ?>	
			<? } ?>	
			<? } ?>
		</select><br><span style="visibility:hidden;"><input type="text" name="bother" size="14" id="bother"></span>
			</div>
		</div>

Open in new window


The first two echos properly display. The 2nd two do not, even thought the value of ctbrand is NOT null.

The attached shows the displayed page; you can see the first two echos.

I'm sure it is something simple, I just cannot see it.

Can someone help?
customize_hvac_partial.JPG
Avatar of Jan Louwerens
Jan Louwerens
Flag of United States of America image

Is it possible that where those echos are in the html makes it invalid html, so it's not showing?

Maybe try writing those echos outside of the select element.
Avatar of Richard Korts

ASKER

To Jan,

The other echos are in the HTML also. On the server, php interprets everything into html. To the browsers it is just text.

I dont think that is the issue.

Richard
Check Richard how you define and assign the $ctbrand variable.
if you are referring to this:
User generated imageThe code take the $ctbrand as empty string so that is the reason that you don't have echo
$ctbrand is echoed on line 15, WITH a value.

The if on line 21 says its null. How does it get null from line 15 to line 21?

Thanks,

Richard
The get_dims()  defines the var again in its scope?
get_dims() is executed with the onChange event. The value of the form variable ctbrand is set to "EVAPCO" (see line 7 in the code), that does not change. The form variable ctbrand is NOT THE SAME as the php variable $ctbrand.

It would be best if respondents to this issue are knowledgeable in HTML, Javascript & php

Richard
ASKER CERTIFIED SOLUTION
Avatar of Jan Louwerens
Jan Louwerens
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
First, I recommend <?php since <? only works when PHP was configured with the --enable-short-tags option. Thus, the shorthand <? doesn't universally work.

Next, you are using print instead of echo when you are attempting to clearly echo $lmodel, assuming these are the two echo's you are seeking since the other echo's in code line sequence won't run while $ctbrand != "". See line #32-33 of my edited code (line #27 of yours with the error).

Lastly, you are echoing these two lines WITHIN the last <SELECT> tag which makes the HTML invalid:
echo "have session ctbrnd = " . $ctbrand . "<br>";
echo "ns = " . $ns . "<br>";

Open in new window


try:

		<div class="row">
			<div class="col-sm-3 col-xs-3"><div style="padding-left:5px;"><?php if ($size == "" && $emsg != "") { ?><span style="color:red;">*&nbsp;</span><?php } ?><u>Select Brand/Model</u></div></div>
			<div class="col-sm-3 col-xs-3"><?php if ($filttype == "") { ?><input type="text" name = "ctbrand" disabled="true"><?php } else { ?>
				<select name="ctbrand" onChange="get_mods();">
					<option value="">-- Select Brand --</option>
					<option value="BAC" <?php if ($ctbrand == "BAC") { ?>selected<?php } ?>>BAC</option>
					<option value="EVAPCO" <?php if ($ctbrand == "EVAPCO") { ?>selected<?php } ?>>EVAPCO</option>
					<option value="SPX/MARLEY" <?php if ($ctbrand == "SPX/MARLEY") { ?>selected<?php } ?>>SPX/MARLEY</option>
					<option value="Other" <?php if ($ctbrand == "Other") { ?>selected<?php } ?>>Other</option>
				</select>
			<?php } ?>	
			</div>
			<div class="col-sm-1 col-xs-1">&nbsp;</div>
<?php 
 echo "filttype = " . $filttype . "<br>"; 
 echo "ctbrand = " . $ctbrand . "<br>"; 
?>
			<div class="col-sm-3 col-xs-3">
<?php if ($filttype == "") {?>
<input type="text" name = "ctmodel" disabled="true">
<?php } else {?>
		<select name="ctmodel" id="ctmodel" onChange="get_dims();">
		<option value="">-- Select Model --</option>
<?php 
		 // if $_SESSION['ctmodel'] is not null, fill array and select the prior one
		 if ($ctbrand != "") {
			for ($i = 0; $i < $ns; $i++) {	
				$ctmod = mysqli_fetch_array($ress,MYSQLI_ASSOC); 
				if ($ctmod['Brand'] == $_SESSION['ctbrand']) {
					$lmodel = $ctmod['Model']; 
?>
					<option value="<?php echo $lmodel; ?>" 
<?php				if ($lmodel == $ctmodel) { ?>selected<?php } ?>><?php echo $lmodel; ?></option>
<?php
				}	
			}
			echo "</select><br>";
			echo "have session ctbrnd = " . $ctbrand . "<br>";
			echo "ns = " . $ns . "<br>";	
		}else{
			echo "</select><br>";
		}
?>
		<span style="visibility:hidden;"><input type="text" name="bother" size="14" id="bother"></span>
			</div>
		</div>

Open in new window

Excellent idea, view source revealed the issue. I had misnamed a variable earlier up in the program.

Thanks