Jump to content

PHP Session Variables and Selectbox Entries


carterlangley

Recommended Posts

Hey there guys,

 

Here is the full code for the page.

<?php
session_start();
include("db_connect.php");
if(($_SESSION['user_id']) && ($_SESSION['access_level'] == 1 ))
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<head>
	<title>Teaching Int Limited - Edit Database</title>
	<meta name="title" content="Teaching Int Limited">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="description" content="Providing Quality English Teachers to Schools and Organisations">
	<meta name="Abstract" content="Providing Quality English Teachers to Schools and Organisations">
	<meta name="keywords" content="TEFL,english,teacher">
	<meta name="Robots" content="index, follow">
	<meta name="Distribution" content="Global">
	<meta name="Revisit-After" content="30 days">
	<meta name="Rating" content="General">
	<meta name="Reply-to" content="[email protected]">
	<meta name="Owner" content="Teaching Int Limited">
	<meta name="Author" content="Carter Langley">
	<meta name="copyright" content="Teaching Int Limited - 2013">
	<link rel="shortcut icon" href="images/favicon.ico">
	<link href='http://fonts.googleapis.com/css?family=Great+Vibes' rel='stylesheet' type='text/css'>
	<link rel="stylesheet" type="text/css" href="form.css">
	<link rel="stylesheet" type="text/css" href="header.css">
	<link rel="stylesheet" type="text/css" href="site.css">
</head>
<body>
<?php include("header.php"); ?><br>

<form class="semantic" method="post" action="">
<fieldset>
<ul>
<li>
<legend>View and/or Edit Person</legend>
<?php
$ops = '';
$sql_select = "select person_id, first_name, middle_name, last_name from `person` order by `last_name` asc ";
$retval_selectperson = mysql_query( $sql_select, $conn );
if(! $retval_selectperson ) { die('Could not select data: ' . mysql_error()); }
while($row = mysql_fetch_assoc($retval_selectperson)) 
{
$ops .=  "<option value='{$row['person_id']}'>{$row['first_name']} {$row['middle_name']} {$row['last_name']}</option>";
}
?>
<div>
<label for="person_id">Select a Person</label>
<select name="person_id" id="person_id">
<option value="">--- Select a Person ---</option>
<?php echo $ops;?>
</select>
</div>
<div class="button-row">
<input type="button" value="Edit Person" id="edit_person" onClick="window.open('edit_person.php')">
</div>
</li>
<li>
<legend>View and/or Edit Company</legend>
<?php
$ops = '';
$sql_select = "select * from `company` order by `company_name` asc ";
$retval_selectcompany = mysql_query( $sql_select, $conn );
if(! $retval_selectcompany ) { die('Could not select data: ' . mysql_error()); }
while($row = mysql_fetch_assoc($retval_selectcompany)) 
{
$ops .=  "<option value='{$row['company_id']}'>{$row['company_name']}</option>";
}
?>
<div>
<label for="company_id">Select a Company</label>
<select name="company_id" id="company_id">
<option value="">--- Select a Company ---</option>
<?php echo $ops;?>
</select>
</div>
<div class="button-row">
<input type="button" value="Edit Company" onClick="window.open('edit_company.php')">
</div>
</li>
<li>
<legend>View and/or Edit Category</legend>
<?php
$ops = '';
$sql_select = "select * from `category` order by `category` asc ";
$retval_selectcategory = mysql_query( $sql_select, $conn );
if(! $retval_selectcategory ) { die('Could not select data: ' . mysql_error()); }
while($row = mysql_fetch_assoc($retval_selectcategory)) 
{
$ops .=  "<option value='{$row['category_id']}'>{$row['category']}</option>";
}
?>
<div>
<label for="category_id">Select a Category</label>
<select name="category_id" id="category_id">
<option value="">--- Select a Category ---</option>
<?php echo $ops;?>
</select>
</div>
<div class="button-row">
<?php $_SESSION['edit_category'] = $_POST['category_id'] ?>
<input type="button" value="Edit Category" onClick="window.open('edit_category.php')">
</div>
</li>
<li>
<legend>View and/or Edit Campus</legend>
<?php
$ops = '';
$sql_select = "select * from `campus` order by `campus_name` asc ";
$retval_selectcampus = mysql_query( $sql_select, $conn );
if(! $retval_selectcampus ) { die('Could not select data: ' . mysql_error()); }
while($row = mysql_fetch_assoc($retval_selectcampus)) 
{
$ops .=  "<option value='{$row['campus_id']}'>{$row['campus_name']}</option>";
}
?>
<div>
<label for="campus_id">Select a Campus</label>
<select name="campus_id" id="campus_id">
<option value="">--- Select a Campus ---</option>
<?php echo $ops;?>
</select>
</div>
<div class="button-row">
<?php $_SESSION['edit_campus'] = $_POST['campus_id'] ?>
<input type="button" value="Edit Campus" onClick="window.open('edit_campus.php')">
</div>
</li>
<li>
<legend>View and/or Edit Documents for a Person</legend>
<?php
$ops = '';
$sql_select = "select person_id, first_name, middle_name, last_name from `person` order by `last_name` asc ";
$retval_selectperson = mysql_query( $sql_select, $conn );
if(! $retval_selectperson ) { die('Could not select data: ' . mysql_error()); }
while($row = mysql_fetch_assoc($retval_selectperson)) 
{
$ops .=  "<option value='{$row['person_id']}'>{$row['first_name']} {$row['middle_name']} {$row['last_name']}</option>";
}
?>
<div>
<label for="person_id">Select a Person</label>
<select name="person_id" id="person_id">
<option value="">--- Select a Person ---</option>
<?php echo $ops;?>
</select>
</div>
<div class="button-row">
<?php $_SESSION['edit_documents'] = $_POST['person_id'] ?>
<input type="button" value="Edit Documents" onClick="window.open('edit_documents.php')">
</div>
</li>
<li>
<legend>View and/or Edit Education for a Person</legend>
<?php
$ops = '';
$sql_select = "select person_id, first_name, middle_name, last_name from `person` order by `last_name` asc ";
$retval_selectperson = mysql_query( $sql_select, $conn );
if(! $retval_selectperson ) { die('Could not select data: ' . mysql_error()); }
while($row = mysql_fetch_assoc($retval_selectperson)) 
{
$ops .=  "<option value='{$row['person_id']}'>{$row['first_name']} {$row['middle_name']} {$row['last_name']}</option>";
}
?>
<div>
<label for="person_id">Select a Person</label>
<select name="person_id" id="person_id">
<option value="">--- Select a Person ---</option>
<?php echo $ops;?>
</select>
</div>
<div class="button-row">
<?php $_SESSION['edit_education'] = $_POST['person_id'] ?>
<input type="button" value="Edit Education" onClick="window.open('edit_education.php')">
</div>
</li>
<li>
<legend>View and/or Edit Employment for a Person</legend>
<?php
$ops = '';
$sql_select = "select person_id, first_name, middle_name, last_name from `person` order by `last_name` asc ";
$retval_selectperson = mysql_query( $sql_select, $conn );
if(! $retval_selectperson ) { die('Could not select data: ' . mysql_error()); }
while($row = mysql_fetch_assoc($retval_selectperson)) 
{
$ops .=  "<option value='{$row['person_id']}'>{$row['first_name']} {$row['middle_name']} {$row['last_name']}</option>";
}
?>
<div>
<label for="person_id">Select a Person</label>
<select name="person_id" id="person_id">
<option value="">--- Select a Person ---</option>
<?php echo $ops;?>
</select>
</div>
<div class="button-row">
<?php $_SESSION['edit_employment'] = $_POST['person_id'] ?>
<input type="button" value="Edit Employment" onClick="window.open('edit_employment.php')">
</div>
</li>
<li>
<legend>View and/or Edit Intake for a Person</legend>
<?php
$ops = '';
$sql_select = "select person_id, first_name, middle_name, last_name from `person` order by `last_name` asc ";
$retval_selectperson = mysql_query( $sql_select, $conn );
if(! $retval_selectperson ) { die('Could not select data: ' . mysql_error()); }
while($row = mysql_fetch_assoc($retval_selectperson)) 
{
$ops .=  "<option value='{$row['person_id']}'>{$row['first_name']} {$row['middle_name']} {$row['last_name']}</option>";
}
?>
<div>
<label for="person_id">Select a Person</label>
<select name="person_id" id="person_id">
<option value="">--- Select a Person ---</option>
<?php echo $ops;?>
</select>
</div>
<div class="button-row">
<?php $_SESSION['edit_intake'] = $_POST['person_id'] ?>
<input type="button" value="Edit Intake" onClick="window.open('edit_intake.php')">
</div>
</li>
</ul>
</fieldset>
</form>						
</body>
</html>
<?php
}
else
{
    echo "<script type=\"text/javascript\">
    alert(\"You don't belong here!\");
    window.location=\"index.php\"</script>";
}

Now, when a button is pressed after a selection is made I need the value of that selectbox to be transfered over to the new page so I can use it in a sql statement to display the record relating to the selection made. I am using sessions anyway, so thought that including a session variable will work, but I can't get it right. Please help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.