Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    passing variables from one file to another

    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:

    Code:
    <?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:
    Code:
    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)

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Depends on the time of year
    Posts
    478
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I doing this off the top of my head so might need some editing

    For second page:

    Code:
    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..
    Last edited by duniyadnd; 04-24-2004 at 05:41 PM. Reason: error in code

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    PHP Code:
    <? // $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']}");?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    New Coder
    Join Date
    Apr 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The things you suggested didn't work...

  • #5
    New Coder
    Join Date
    Apr 2004
    Location
    Texas
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    perhaps this?
    Code:
    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;
    
    }
    Jason B

  • #6
    New Coder
    Join Date
    Apr 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    Code:
    <?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=
    Last edited by romram; 04-25-2004 at 10:14 AM.

  • #7
    New Coder
    Join Date
    Apr 2004
    Location
    Texas
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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....
    Last edited by black3842; 04-25-2004 at 10:04 AM.
    Jason B

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    And since HTTP_GET_VARS hasn't been used since 4.2.0 you should be using $_GET


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •