Form - passing variables to be displayed on new web page

Hello,

I have an issue where by I wish to pass three values from an originating page to a subsequent page. The intention in future is to pass the values from the originating page to execute a php script with variables attached.

Anyway the first page has three drop down boxes which retrieve the correct values from the MySQL database, however when the “Submit” button is pressed the next page does not display the submitted values. Any insight/advice would be welcomed.

– First script

[code]

<?php require "config.php"; // Your Database details ?> <? // variables to change query1, result11, dropdown11 // query1 $query1 = "SELECT LANG, LANG_ID FROM LANG"; // Execute it, or return the error message if there's a problem. $result1 = mysql_query($query1) or die(mysql_error()); // query2 $query2 = "SELECT LANG, LANG_ID FROM LANG"; // Execute it, or return the error message if there's a problem. $result2 = mysql_query($query2) or die(mysql_error()); // query3 $query3 = "SELECT SUBJECT, SUBJECT_ID FROM SUBJECT"; // Execute it, or return the error message if there's a problem. $result3 = mysql_query($query3) or die(mysql_error()); // dropdown1 $dropdown1 = ""; while($row = mysql_fetch_assoc($result1)) { $dropdown1 .= "\r\n{$row['LANG']}"; } $dropdown1 .= "\r\n"; echo "Language 1: "; echo $dropdown1; // dropdown2 //Language 2: $dropdown2 = ""; while($row = mysql_fetch_assoc($result2)) { $dropdown2 .= "\r\n{$row['LANG']}"; } $dropdown2 .= "\r\n"; echo " Language 2: "; echo $dropdown2; // dropdown3 $dropdown3 = ""; while($row = mysql_fetch_assoc($result3)) { $dropdown3 .= "\r\n{$row['SUBJECT']}"; } $dropdown3 .= "\r\n"; echo " Subject: "; echo $dropdown3; $dropdown1 = $_POST["dropdown1"]; $dropdown2 = $_POST["dropdown2"]; $dropdown3 = $_POST["dropdown3"]; echo ""; mysql_close($con); ?> [/code]

– Second script. It is named process.php

[code]

<?php echo $dropdown1 echo $dropdown2 echo $dropdown3 ?> [/code]

thanks
Steve

Hi Steve,

There are three problems with your code.

First of all, your first two select tags have the same name:

Secondly, the $_POST variable is referencing to the wrong field. You do not have any html element with the name dropdown1, dropdown2 and dropdown3.

$dropdown1 = $_POST[“dropdown1”];
$dropdown2 = $_POST[“dropdown2”];
$dropdown3 = $_POST[“dropdown3”];

Your code should be:
$dropdown1 = $_POST[“LANG”];
$dropdown2 = $_POST[“LANG”];
$dropdown3 = $_POST[“SUBJECT”];

However, as i’ve pointed out earlier, you shouldn’t have the same name for the select tags. But just for the purpose of showing you the correct reference, i’m accessing $_POST[“LANG”] twice which will not get the right value.

Thirdly, the $_POST variable should be in process.php file.

Regards,
developer.dex2908

Hi,

thanks very much for taking the time to look at this query. Everything is now working perfectly through following your suggestions.

Steve

Hi steve,

Glad i could help… you are welcome ;D

Regards,
developer.dex2908

Sponsor our Newsletter | Privacy Policy | Terms of Service