catching a variable in a include file

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
justinb
Forum Newbie
Posts: 11
Joined: Fri Dec 06, 2002 12:11 am

catching a variable in a include file

Post 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
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post 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?
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post 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"; ?>
justinb
Forum Newbie
Posts: 11
Joined: Fri Dec 06, 2002 12:11 am

Post by justinb »

thansk nathus,
It looks like its close, but what is happneing now, is the ddl on confirm page, is just not there
justinb
Forum Newbie
Posts: 11
Joined: Fri Dec 06, 2002 12:11 am

Post by justinb »

thansk nathus,
It looks like its close, but what is happneing now, is the ddl on confirm page, is just not there
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post 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>";
justinb
Forum Newbie
Posts: 11
Joined: Fri Dec 06, 2002 12:11 am

Post 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.
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post by nathus »

getting any error messages? it works on my test server. /shrug
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

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