Solved

Using var. from URL

Posted on 2004-04-25
3
194 Views
Last Modified: 2013-11-18
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;
}
}
?>

[/code]

When pressing the submit button, the page will alwayes consider the statement "if (empty($assigTitle))" true
and I get the following URL
[url]http://localhost/inst_add_assig.php?co=&sec=%20enctype=[/url]
0
Comment
Question by:COMPUTER_SC_STUDENT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Accepted Solution

by:
jkna_gunn earned 125 total points
ID: 10911322
instead of adding the variables in the action part of the form tag
create hidden inputs inside your form

<form method="POST" action="inst_add_assig.php">
.. rest of form stuff
<input type="hidden" name="co" value="<?=$co?>">
<input type="hidden" name="sec" value="<?=$sec?>">
</form>

also i cant see where $assigTitle is getting initialised???

should you not have something like

$assignTitle = $_POST["assigTitle"];

before the if statment
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question