...

View Full Version : passing variables from one file to another



romram
04-24-2004, 02:12 PM
I have two files one is the one where I have variable taken from the get method, and I want to pass again to the second page.

first page:




<?php
include 'include.inc';

// Connect to a session
session_start();

?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Manage Assignments</title>
<link rel="stylesheet" href="style.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>

<body bgcolor="#FFFFe8">

<div id="Layer1" style="position:absolute; left:0px; top:0px; width:508px; height:52px; z-index:1"><img src="logo/eSubmissionbannerBigLighter.jpg" width="783" height="69"></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<?php
$co=$_GET["courseName"];
echo "***".$co;
echo "
<form name=\"form1\" method=\"GET\" action=\"manage_buttons.php?course=$co\"> ";?>
<?php


function selectDistinct ($connection,
$tableName,
$columnName,
$pulldownName,
$additionalOption,
$defaultValue)
{

$defaultWithinResultSet = FALSE;
/* if (!($connection = @ mysql_connect($hostName,
$username,
$password)))
die("Could not connect to database");

if (!mysql_select_db($databaseName))
showerror();*/

if (session_is_registered("loginUsername"))
{
$insID=$_SESSION["loginUsername"];
}


$query= "SELECT * FROM course
WHERE course_name = '".$_GET["courseName"]."'";


if (!($courseNo = @ mysql_query ($query,
$connection)))
showerror();

$row = mysql_fetch_array($courseNo);

// Query to find distinct values of $columnName
// in $tableName
$distinctQuery = "SELECT DISTINCT $columnName
FROM $tableName
WHERE inst_id=$insID AND
s.course_no='" . $row["course_no"] . "'";




// Run the distinctQuery on the databaseName
if (!($resultId = @ mysql_query ($distinctQuery,
$connection)))
showerror();


// Retrieve all distinct values
$i = 0;
while ($row = @ mysql_fetch_array($resultId))
$resultBuffer[$i++] = $row[$columnName];

// Start the select widget
echo "\n<select name=\"$pulldownName\">";


/* // Is there an additional option?
if (isset($additionalOption))
// Yes, but is it the default option?
if ($defaultValue == $additionalOption)
// Show the additional option as selected
echo "\n\t<option selected>$additionalOption";
else
// Just show the additional option
echo "\n\t<option>$additionalOption";

// check for a default value
if (isset($defaultValue))
{
// Yes, there's a default value specified

// Check if the defaultValue is in the
// database values
foreach ($resultBuffer as $result)
if ($result == $defaultValue)
// Yes, show as selected
echo "\n\t<option selected>$result";
else
// No, just show as an option
echo "\n\t<option>$result";
} // end if defaultValue
else
{ */
// No defaultValue

// Show database values as options
foreach ($resultBuffer as $result)
echo "\n\t<option>$result";

// }
echo "\n</select>";
} // end of function



?>

<table width="75%" border="0" align="center">
<tr>
<td width="66%"><strong>Select a section:</strong></td>
<td width="34%">
<?php // Connect to the DBMS
if (!($connection = @ mysql_connect($hostName,
$username,
$password)))
die("Could not connect to database");

if (!mysql_select_db($databaseName))
showerror();


// Produce the select list
// Parameters:
// 1: Database connection
// 2. Table that contains values
// 3. Attribute that contains values
// 4. <SELECT> element name
// 5. An additional non-database value
// 6. Optional <OPTION SELECTED>
selectDistinct($connection,
"section s, course c",
"section_no",
"sectionNum",
"",
"");

$courseName=$_GET[courseName];
echo "****".$courseName;
//<a href=\"inst_view_assig.php?courseName=$courseName\">
?>
</td>
</tr><?php
echo "<tr>

<td height=\"21\" colspan=\"2\"><div align=\"center\"><input name=\"ViewAss\" value=\"ViewAss\" type=\"submit\" class=\"button\"></div></td>
</tr>
<tr>
<td height=\"21\" colspan=\"2\"><div align=\"center\"><strong>or</strong></div></td>
</tr>
<tr>
<td height=\"21\" colspan=\"2\"><div align=\"center\"><input name=\"AddAss\" value=\"AddAss\" type=\"submit\" class=\"button\"></div></td>
</tr>
<tr>
<td height=\"21\" colspan=\"2\"><div align=\"center\"><strong>or</strong></div></td>
</tr>
<tr>
<td height=\"21\" colspan=\"2\"><div align=\"center\"><input name=\"GradeRec\" value=\"GradeRec\" type=\"submit\" class=\"button\"></div></td>
</tr>
";?>
</table>
</form>
<p>&nbsp;</p>
</body>
</html>


The second page:


if (!empty($parameters["ViewAss"]))
{
// Redirect the browser to the customer account page
// using the HTTP response header "Location:"
header("Location: view_dir.php");
exit;
}

if (!empty($parameters["AddAss"]))
{
// Redirect the browser to the customer account page
// using the HTTP response header "Location:"
// $c=$_GET["course"];
$s=$_GET["sectionNum"];

header("Location: inst_add_assig.php?c=$s&cor=$course");
exit;
}



I get the url with cor= (empty) :confused:

duniyadnd
04-24-2004, 04:58 PM
I doing this off the top of my head so might need some editing

For second page:




if ($ViewAss) {


header("Location: view_dir.php");

}

else if ($AddAss) {

// Redirect the browser to the customer account page
// using the HTTP response header "Location:"
$c=$_GET["course"];
$s=$_GET["sectionNum"];

header("Location: inst_add_assig.php?c=$s&cor=$_GET['course']");
exit;

}


Might be a problem, cause I didn't really go through your code.. so let me know.. :p

firepages
04-24-2004, 05:39 PM
<? // $c=$_GET["course"]; ?>
try removing the comments
<? $c=$_GET["course"]; ?>
and then use
<?header("Location: inst_add_assig.php?c=$s&cor=$c");?>
or plain
<?header("Location: inst_add_assig.php?c={$_GET['sectionNum']}&cor={$_GET['course']}");?>

romram
04-25-2004, 08:10 AM
The things you suggested didn't work... :( :confused:

black3842
04-25-2004, 08:41 AM
perhaps this?


header("Location: view_dir.php");

}

else if ($AddAss) {

// Redirect the browser to the customer account page
// using the HTTP response header "Location:"
$c=$_GET["course"];
$s=$_GET["sectionNum"];

header("Location: inst_add_assig.php?c=$s&cor=$c");
exit;

}

romram
04-25-2004, 09:17 AM
Now the problem is that we see the variables in the URL, but it is empty in the body of the script:

URL: "http://localhost/inst_add_assig.php?sec=99&co=9990"

page: inst_add_assig.php



<?php
include 'include.inc';
session_start();

if (empty($assigTitle)){
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Add an Assignment</title>
<link rel="stylesheet" href="style.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>

<body bgcolor="#FFFFe8">

<div id="Layer1" style="position:absolute; left:0px; top:0px; width:508px; height:52px; z-index:1"><img src="logo/eSubmissionbannerBigLighter.jpg" width="783" height="69"></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<?php echo"
<form name=\"form1\" method=\"post\" action=\"inst_add_assig.php?co=".$co."&amp;sec=".$sec." enctype=\"multipart/form-data\">";?>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">

<table width="75%" border="0" align="center">
<tr>
<td><strong>Enter file name:</strong></td>
<td><input type="file" name="uploadedFile" class="textfield"></td>
</tr>
<tr>
<td><strong>Enter assignment title:</strong></td>
<td><input type="text" name="assigTitle" class="textfield"></td>
</tr>
<tr>
<td height="26"><strong>Due date:</strong></td>
<td> <select name="select" class="select">
</select> <select name="select2" class="select">
</select> <select name="select3" class="select">
</select> </td>
</tr>
<tr>
<td height="21"><strong>Files to be included:</strong></td>
<td height="21"><input type="text" name="textfield3" class="textfield"></td>
</tr>
<tr>
<td height="113" colspan="2"><div align="center">
<p>
<input type="submit" >
</p>
</div></td>
</tr>
</table>
</form>

<p>&nbsp;</p>
</body>
</html>



<?php
}
else if (!empty($assigTitle))
{


if($HTTP_POST_FILES['uploadedFile']['size'] <=0)
{
print"<b>Not recieved.</b><br>";
}
else
{
$assig=$_POST['assigTitle'];
//$sect= $sec;
//$cour= $_POST['courseName'];
$username = strtolower($_SESSION["loginUsername"]);
$dir = "instructor/" . $username . "/" . $assig . "/";
if(!file_exists($dir))
mkdir($dir,0700);

echo "***".$sec."***".$co;

/******************************/

//$assig=$_REQUEST['assigTitle'];
//$username = strtolower($_SESSION["loginUsername"]);
$destination= "instructor/" . $username . "/". $assig . "/".$HTTP_POST_FILES['uploadedFile']['name'];

copy($HTTP_POST_FILES['uploadedFile']['tmp_name'],$destination);
//$HTTP_POST_FILES['uploadedFile']['name']);
echo "******". $destination;
}
}
?>



When pressing the submit button, the page will alwayes consider the statement "if (empty($assigTitle))" true
and I get the following URL
http://localhost/inst_add_assig.php?co=&sec=%20enctype=

black3842
04-25-2004, 09:58 AM
shouldn't these lines

$sec= $HTTP_GET_VARS['sectionNum'];
$cour= $HTTP_GET_VARS['courseName'];

be
$sec= $HTTP_GET_VARS['sec'];
$cour= $HTTP_GET_VARS['co'];

since those are what you passed in your get.....not sure, I don't exactly follow the logic of your code....I didn't read it all......not both files anyway....I'm at work....

Nightfire
04-25-2004, 01:05 PM
And since HTTP_GET_VARS hasn't been used since 4.2.0 you should be using $_GET



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum