Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dropdown session problem

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
Hi,

Could someone tell me from the following code how can I pass the following
id's to another page

id_interest
id_subject
id_level

What I want to do is pass these values to another page then convert
them to sessions. Isit possible to convert them to sessions on this page.

I'm quite new to this stuff so a basic explanation of transferring dropdown
variables would be great.

Many tks

Gaz

---------------------------- Code for step one ---------------------------


<?php
// Include the configuration file
require_once ('includes/config.inc');

// Set the page title and include the header
$page_title = 'findagrind home page';

// Include the header file
include_once ('includes/header.htm');

require_once('../Connections/findagrind.php');

mysql_select_db($database_findagrind, $findagrind);

$query_Recordset1 = "SELECT interests.id_interest,interest_name,
subjects.id_subject,subject_name,levels.id_level,level_name
FROM interests,levels,subjects
WHERE interests.id_interest = levels.id_interest
AND interests.id_interest = subjects.id_interest
ORDER BY interest_name,subject_name,level_name ";

$Recordset1 = mysql_query($query_Recordset1, $findagrind) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>


<!-- Start of Content Div -->
<div id = "content">

<h2>Step One: Grind Information</h2>

<?php

// Validate the log-in details
if (isset($_POST['submit']))
// Check if the form has been submitted
{


ob_end_clean();
header("Location: . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/step2.php");
exit();

// Close the database connection
mysql_close();

// End of check if form has been submitted
}

?>

<form name = "signup" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<select name="interest" id="interest" onChange="TCN_reload(this)">
<option selected>interest</option>
</select>
<select name="subject" id="subject" onChange="TCN_reload(this)">
<option selected>subject</option>
</select>
<select name="level" id="level" onChange="TCN_reload(this)">
<option selected>level</option>
</select>



<script language="JavaScript">
the javascript code is here
</script>

<table align="center">
<td colspan="2" class="labelcell"><label for = "confirm_password"></label></td>
<td colspan="2" align="center"><input type="submit" name="submit" value="Log-In"/></td>
</table>
</form>


</div>
<!-- End of Content Div -->


<?php
// Include the footer
include_once('includes/footer.htm');
mysql_free_result($Recordset1);
?>
 
Getting values from a form to a session is not hard:

The user submits the form to a PHP script.
The PHP script takes the values from the submitted info and puts them in session variables.


Typically, the structure of a PHP script that both produces a form for user input or processes the info from that form has the structure:

Code:
<?php
session_start();

if (isset ($_POST['foo']))
{
   $_SESSION['foo'] = $_POST['foo'];
   $_SESSION['bar'] = $_POST['bar'];
}
else
{
   print '
   <html>
      <body>
         <form method="post" action="' . $_SERVER['PHP_SELF'] . '">
            <input type="text" name="foo"><br>
            <input type="text" name="bar">
            <input type="submit">
         </form>
      </body>
   </html>';
}
?>

Each time it is run, the script either produces the form for user input or processes input submitted, but not both. Your script appears to try to do both at once.

Putting values into a session variable can be one of the steps of processing the data.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Tks Tanstaaf,

But when getting info from a dropdown from the select statement example.

<select name="interest" id="interest" onChange="TCN_reload(this)">
<option selected>interest</option>
</select>

How can i make the id_interest which is coming from the SQL
statement into a POST variable.

I can understand the concept with a standard text input box,
but from a dropdown I can't grasp the idea

Tks again



 
Inspect the POST array in the receiving script by adding:
Code:
print_r($_POST);

You will see that all form elements are present by "name" and hold the selected values as value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top