redirection after submission of page not working in ie 7

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harikamat
    New Member
    • Jul 2009
    • 3

    redirection after submission of page not working in ie 7

    Hi,

    I have a form which allows user to upload image. On submission of the form the data is inserted into the mysql database and image is copied into a directory. After this i try to redirect the user to the form which gives error in IE 7.This form works perfectly in Mozilla Fire Fox.

    The form has one text box, file browse option and a submit button. The enctype of the form is set to multipart form data.

    I really cannot why the IE 7 is giving error. Below is the message displayed by IE 7

    Internet Explorer cannot display the webpage

    Most likely causes:
    You are not connected to the Internet.
    The website is encountering problems.
    There might be a typing error in the address.

    What you can try:

    Cany anyone help me.

    Thanks

    Harish
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    No idea of what the error could be caused by without seeing the form markup.. so post it?

    Comment

    • harikamat
      New Member
      • Jul 2009
      • 3

      #3
      Originally posted by Markus
      No idea of what the error could be caused by without seeing the form markup.. so post it?

      Hi Markus,

      Below is the form markup, followed by the PHP code file which is called on submission of the form.

      Code:
      <html>
      <head>
      
      <title>[url]www.jettoner.com[/url] - Admin Panel</title>
      <link href="../style.css" rel="stylesheet" type="text/css">
      <script type="text/javascript">
      
      
      function check()
      {
         
      
               var ok=1;
      		if(isEmpty( document.myform.Category_Name.value ))
      		{
      			alert("Please enter Category Name");
      			document.myform.Category_Name.value = "";
      			document.myform.Category_Name.focus();
      				
      				ok=0;
      			return false;
      		}
      
      		
      	    if(ok==1)
      		{
      
      	     document.myform.submit();	
      		}
      
      
      }
      
      function isEmpty( str ){ 
          var strRE = /^[\s ]*$/gi; 
          return strRE.test( str ); 
      } 
      
      
      </script>
      
      </head>
      
      <body >
      
      <table cellspacing="0" cellpadding="0" border="1" width="920" align="center" >
      <tr><td  height="40" class="mainheading">
      <?php getGIHeader(); ?>
      
      </td></tr>
      <tr><td>
      <table width="99%" border="0">
      <tr><td width="10%" valign="top">
      
      <? getGILeftPane(); ?>
      
      </td>
      <td width="50%" align="center" valign="top">
      
      <table cellspacing="0" cellpadding="0" border="0" width="95%" align="center" >
      <tr><td class="mainheading">
      Add Category
      <br><br>
      </td></tr>
      <tr><td>
      <!-- Data entry form starts here -->
      <form action='AddCategory1.php' method='post' name="myform" enctype="multipart/form-data"> 
      <table cellspacing="0" cellpadding="0" border="0" width="55%" align="left" >
      <tr><td colspan="2" class="messageHeading" height="30" align="center"> <?php echo $errorMessage;  ?></td></tr>
      <tr><td align="center" height="30">Category:</td><td><input type="text" name="Category_Name" value="<?php echo $row['Category_Name']; ?>"></td></tr>
      <tr><td align="center" height="30">Image:</td><td><input type="file" name="file1" ></td></tr>
      <tr><td></td><td><br><input type="Button" name="Submit" value="Submit" onClick=check()></td></tr>
      </table>
      <!-- Data entry form ends here -->
      </form>
      </td></tr>
      </table>
      </td>
      </tr>
      </table>
      </td></tr>
      </table>
      
      </body>
      
      </html>
      PHP page that executes the code on submission of the form:

      Code:
      <?php
      
      require_once('../includes/Common.php');
      require_once('../includes/DbConnector.php');
      
      // Create an instance of DbConnector
          $connector = new DbConnector();
      
      
      
      // check whether category name exists, if yes redirect to the Add Category page
      $selStatement ="select * from Category where Category_Name='".$_POST["Category_Name"]."'";
      
      	if (!($result = $connector->query($selStatement)))
      	{
             $_SESSION["Message"] = "Error occured while processing the request!";
      	   header("location:/salesdemo/management/Message.php");
      	   exit;
      	}
      
      	$RowCount = $connector->fetchNoOfRows($result);
      
      
      If($RowCount == 1)
      {
      		//echo "inside RowCount = $RowCount";
      	//exit;
      
      	//  set up a $lastformVars array to store the previously entered data
      	$lastformVars = array();
      	$lastformVars["Category_Name"] = $_POST['Category_Name'];
      	
      
      	// Save the array as a sesssion variable
      	$_SESSION["lastformVars"] = $lastformVars;
      
      	// Store the $errors array as a session variable
      	$_SESSION["errors"] = $errors;
      
             $_SESSION["Message"] = "Category Name already exists!";
                  header("location:AddCategory.php");
      			exit;
      
      }
      else
      {
      $uploaddir = "../CategoryImages"; 
      // The Upload Part
      if(is_uploaded_file($_FILES['file1']['tmp_name']))
      {
      //move_uploaded_file($_FILES['file1']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
      //$Cat_Image = $_FILES['file1']['name'];
      //print "Your file has been uploaded successfully! Yay!";
      //exit;
      
      if(move_uploaded_file($_FILES['file1']['tmp_name'], $uploaddir.'/'.$_FILES['file1']['name'])) {
         // echo "The file ".  basename( $_FILES['file1']['name']). 
          " has been uploaded";
      	$Cat_Image = $_FILES['file1']['name'];
      	
      } else{
          //echo "There was an error uploading the file, please try again!";
      	//echo $uploaddir.'\\'.$_FILES['file']['name'];
      	$Cat_Image = "";
      	
      }
      
      
      
      } else {
      //print "Incorrect file extension!";
      $Cat_Image = "";
      }
      
      // Create insert statement
      $statement ="insert into Category(Category_Name,Category_Image) values('".trim($_POST["Category_Name"])."','".$Cat_Image."') ";  
                    	// Save the form data into the database 
      				//echo $statement;
      				//exit;
               if ($result = $connector->query($statement)){
      
                   // It worked, give confirmation
      			
                  $_SESSION["Message"] = "Successfully added Category !";
      			//echo $_SESSION["Message"];
                  header('location:AddCategory.php');
      			exit;
      
              }else{
      
                 // It hasn't worked so stop. Better error handling code would be good here!
                  $_SESSION["Message"] = "Error occured while adding Category !";
                  header("location:AddCategory.php");
      			exit;
      
              }
      
      
      }
      
      
      ?>
      Last edited by Markus; Aug 1 '09, 10:03 AM. Reason: Added [code] tags.

      Comment

      • unauthorized
        New Member
        • May 2009
        • 81

        #4
        Enable output buffering for this script (will degrade performance) or replace header() redirect with a JS redirect.

        Look up the php docs on header() for more info.

        Comment

        • harikamat
          New Member
          • Jul 2009
          • 3

          #5
          Originally posted by unauthorized
          Enable output buffering for this script (will degrade performance) or replace header() redirect with a JS redirect.

          Look up the php docs on header() for more info.

          Cannot enable output buffering because the php script is used only to add record to the mysql db and then redirect user again to the AddCategory.php page, Even if error occurs in AddCategory1.ph p script the user is redirected to the AddCategory.php page using header().

          Comment

          Working...