Page 1 of 1

catching a variable in a include file

Posted: Fri Dec 20, 2002 12:37 pm
by justinb
Hello i have a tricky problem
i have a form which when filled sends the users to a confirm page, One of the elements is a dropdownlist, what i want is for the confirm drop down list to display the information from the first drop down list. Now this DDL is an include file which i put in my form.

this is the first one from the first form, this code is in an include file which is inserted into the form

$sql = "SELECT catID, catName
FROM $table_name
ORDER BY catID";

$result = @mysql_query($sql, $connection) or die("Error3 - Couldn't connect - please try later.");

while($row = @mysql_fetch_array($result))
{ //start while
$row

$catID = $row['catID'];
$catName = $row['catName'];

$option_block .= "<option value='$catID'>$catName</option>";

} //end while

$display_block = "<select name='$catID'><option>Choose an Industry</option>$option_block<option value='O'>Other</option></select>";
?>

<? echo "$display_block"; ?>

and it works fine, this is what i have down to try to catch it on the confirm page, but it doesn't work. i want to give the user the option to modify their category here


$id = '$_REQUEST[catID]';

$sql = "SELECT catID, catName
FROM $table_name
ORDER BY catID";

$result = @mysql_query($sql, $connection) or die("Error3 - Couldn't connect - please try later.");


while($row = @mysql_fetch_array($result))
{ //start while
$row

$catID = $row['catID'];
$catName = $row['catName'];

$option_block .= "<option value='$catID'>$catName</option>";

} //end while

$display_block = "<select name='$catID'><option>Choose an Industry</option><option value="$id">$catName</option>$option_block<option value='O'>Other</option></select>";
?>

<? echo "$display_block"; ?>

any help would be appreciated

Posted: Fri Dec 20, 2002 12:49 pm
by nathus
let me see if I understand what you're asking.
on the confirm page you want the choice that was selected on the previous page to be selected in the drop down list?

Posted: Fri Dec 20, 2002 12:58 pm
by nathus
ok, this might be what you want.

Code: Select all

$id = '$_POST[catID]'; 

$sql = "SELECT catID, catName 
FROM $table_name 
ORDER BY catID"; 

$result = @mysql_query($sql, $connection) or die("Error3 - Couldn't connect - please try later."); 


while($row = @mysql_fetch_array($result)) 
{ //start while 
$row 

$catID = $row['catID']; 
$catName = $row['catName']; 
if ($catID == $id) {
$option_block .= "<option value='$catID' selected='selected'>$catName</option>"; 
}
else {
$option_block .= "<option value='$catID'>$catName</option>"; 

}

} //end while 

$display_block = "<select name='$catID'><option>Choose an Industry</option><option value="$id">$catName</option>$option_block<option value='O'>Other</option></select>"; 
?> 

<? echo "$display_block"; ?>

Posted: Fri Dec 20, 2002 4:10 pm
by justinb
thansk nathus,
It looks like its close, but what is happneing now, is the ddl on confirm page, is just not there

Posted: Fri Dec 20, 2002 4:25 pm
by justinb
thansk nathus,
It looks like its close, but what is happneing now, is the ddl on confirm page, is just not there

Posted: Fri Dec 20, 2002 4:32 pm
by nathus
change the line that echo's the display block to this. also in the first file, should change it from $catID to catID for the name of the select form.

$display_block = "<select name='catID'><option>Choose an Industry</option>$option_block<option value='O'>Other</option></select>";

Posted: Fri Dec 20, 2002 5:42 pm
by justinb
ok,
i changed it in the confirm file, the first file was allready like that.

no different, the display block is not showing up at all.

Posted: Fri Dec 20, 2002 5:48 pm
by nathus
getting any error messages? it works on my test server. /shrug

Posted: Sat Dec 21, 2002 11:44 pm
by evilcoder
try calling the items in your confirm page with $_POST['fieldname']

dunno, just a suggestion, haven't realy taken the time to look roperly at the code and the problem.