The LAST statement in the "while" loop in the program is used to create a drop-down list of country codes in the html form. Within each "option" tag for this country drop down, I want a bit of PHP too - and that is to just test to see if a value had been entered before we went off to edit the submitted values...and if so, I'll retain that user's entered value when the screen is displayed again (when an edit error is detected, the form is re-displayed so the user can correct whatever errors may exist).
The script is just in a rough 'test' mode right now. For instance, it doesn't even have any real edits in it (I make each 'submit' fail as if there were edit issues for now).
I want to focus on the creation of the country code drop-down list in this thread.
I think that the 'problem' is that the php code that is inserted WITHIN the <option> tags for the country code drop-down are not being recognized as code... (note that the drop down list that is included in the form just before this 'country code' stuff also has embedded php statements to test for saveoff field values - for the same reason as what I'm attempting with the php-constructed country code drop-down - and the embedded php statements in that prior drop down seem to work just fine).
I'd appreciate your help in determining what I should do differently when programatically building the country code drop down - specifically on the point of getting that embedded PHP (which tests $savecou) to work - and to be recognized as code.
One last point: the "input file" that is read in this script (called "countries.txt") contains 4 "records" - and each record has 3 comma-delimitted fields - the first of which is the textual 'country name'.
To try out the code as it exists today, you can see: http://bandyak.co.cc/persc.php
Your assistance is GREATLY appreciated!
here is the script in it's current (rough) state:
Code: Select all
<?php
$Mobile = $_POST["Mobile"];
$Carrier = $_POST["Carrier"];
$Country = $_POST["Country"];
top:
if (!isset($_POST['submit'])) { // if not yet submitted then display the main form
?>
<html>
<head>
<title>title stuff</title>
</head>
<body bgcolor="#203302" text="#0EEFFF" link="#FFFFFF" vlink="#CCCCCC" alink="#33FFFF">
<div id="Layer1" style="position:absolute; z-index:3; left: 17%; top: 20%;">
<form method="post" action="<?php echo $PHP_SELF;?>" onReset="return confirm('Do you really want to reset the form?')"
>
MOBILE#:<input type="text" size="10" maxlength="10" name="Mobile" value="<?php echo $savemobl;?>">
CARRIER:<select name="Carrier">
<option value="" <?php if ($savecarr == '') print 'selected'; ?>> </option>
<option value="ATT" <?php if ($savecarr == 'ATT') print 'selected'; ?>>AT&T</option>
<option value="Sprint" <?php if ($savecarr == 'Sprint') print 'selected'; ?>>Sprint</option>
<option value="TMobile" <?php if ($savecarr == 'TMobile') print 'selected'; ?>>TMobile</option>
<option value="Verizon" <?php if ($savecarr == 'Verizon') print 'selected'; ?>>Verizon</option></select>
<?
$htmlco = 'COUNTRY:<select name=\"Country\">';
$myFile = 'countries.txt';
$fh = fopen($myFile, "r");
while(! feof($fh))
{
$theData = fgets($fh);
$piece = explode(",", $theData);
[b]$htmlco = $htmlco.'<option value ="'.$piece[0].'"'.' <?php if ($savecou=="'.$piece[0].'") print "selected"; ?> >'.$piece[0].'</option>';[/b]
}
fclose($fh);
$htmlco = $htmlco.'</select><br />';
echo $htmlco;
?>
<input type="submit" value="Update Now!" name="submit">
<INPUT TYPE=RESET VALUE="Cancel">
</form>
</div>
<?
} else {
$e = '';
if (editpers($e) != '') {
?>
<html>
<head>
<title></title>
</head>
<body>
<form method=get action="whereveryouwant.com" onSubmit="return false;">
(EXPERIMENTING ONLY HERE - EDITS FORCED TO FAIL) THERE IS A PROBLEM WITH YOUR INFO<br />
<input type="submit">
</form>
<?
$savemobl = $Mobile;
$savecarr = $Carrier;
$savecou = $Country;
unset($_POST['submit']);
goto top;
}
else {
echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";
foreach ($genre as $g) { echo $g."<br />"; }
echo "<i>".$quote."</i><br />";
}
}
?>
<?php
function editpers($epmsg)
{
$epmsg = 'state field is incorrect, please try again';
return $epmsg;
}
?>