arcticfox Posted April 24, 2009 Share Posted April 24, 2009 Hi, I currently have a form which sends data to a php page, this page is meant to upload a file to my server and then add some data to a sql database and finally redirect the user to an appropriate page. This code works perfectly in Firefox, however if I use it in IE the page is not redirected and i get the IE error page: Cannot display the web page. Here is the code for the php page with the issue: <?php session_start(); if(!session_is_registered("myusername")){ header("location:login.php"); } ?> <?php // Check Type if ($_POST['type'] == "News" || $_POST['type'] == "Main"){ $host= // Host name $username= // Mysql username $password= // Mysql password $db_name= // Database name // Connect to server and select databse. $connection = mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // data sent from form $title=$_POST['title']; $type=$_POST['type']; $link=$_POST['link']; $summary=$_POST['summary']; $body=$_POST['body']; // To protect MySQL injection $title = stripslashes($title); $type = stripslashes($type); $link = stripslashes($link); $summary = stripslashes($summary); $body = stripslashes($body); $title = mysql_real_escape_string($title); $type = mysql_real_escape_string($type); $link = mysql_real_escape_string($link); $summary = mysql_real_escape_string($summary); $body = mysql_real_escape_string($body); // Test for null values if($title == "" || $summary == "" || $body == "" ){ mysql_close($connection); header("location:{$type}type.php?error=2"); exit; } else{ $sql="insert into tblContent (title, summary, body, type, DateStamp, link) values ('$title', '$summary', '$body', '$type', NOW(), '$link')"; $result=mysql_query($sql); // Success = 1 if($result==1){ mysql_close($connection); header("location:content.php"); exit; } else { mysql_close($connection); header("location:{$type}type.php?error=1"); exit; }} } // END TYPE SET // Banner Type Set else if($_POST['type'] == "Banner"){ // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { $host= // Host name $username= // Mysql username $password= // Mysql password $db_name= // Database name // Connect to server and select databse. $connection = mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // data sent from form $title=$_POST['title']; $type=$_POST['type']; $link=$_POST['link']; // To protect MySQL injection $title = stripslashes($title); $type = stripslashes($type); $link = stripslashes($link); $title = mysql_real_escape_string($title); $type = mysql_real_escape_string($type); $link = mysql_real_escape_string($link); // Test for null values if($title == "" || $type == "" || $link == "" ){ mysql_close($connection); header("location:bannertype.php?error=2"); exit; } else{ $sql="insert into tblContent (title, type, DateStamp, link, filename) values ('$title', '$type', NOW(), '$link', '".basename( $_FILES['uploadedfile']['name'])."')"; $result=mysql_query($sql); // Success = 1 if($result==1){ mysql_close($connection); header("location:content.php"); exit; } else { mysql_close($connection); header("location:bannertype.php?error=1"); exit; } } } // END UPLOAD IF // Error for file failure else{ header("location:bannertype.php?error=3"); exit;} } // END TYPE SET else{ echo "Error: No Type Was Defined!"; } ?> The problem is definatly only with the Banner part of the code as the first section works fine. I have a feeling its to do with the Header () command but have been unable to find any information that has helped me to solve this issue. I would be greatful if anyone could point out the problem with my code. Thankyou in Advance Arcticfox Quote Link to comment https://forums.phpfreaks.com/topic/155512-ie-cannot-display-the-web-page/ Share on other sites More sharing options...
premiso Posted April 24, 2009 Share Posted April 24, 2009 } ?> <?php That will cause an issue with header tags, as there is a space there that is considered a "white space" and constitute output being sent to the browser. There is also no need for that so just remove the php tags from there and see if that solves the problem. Also please use instead of the quote tags to surround code. Quote Link to comment https://forums.phpfreaks.com/topic/155512-ie-cannot-display-the-web-page/#findComment-818319 Share on other sites More sharing options...
JonnoTheDev Posted April 24, 2009 Share Posted April 24, 2009 Check the url in the header() function that you are redirecting to by printing it. It maybe malformed. Firefox maybe able to reconstruct it correctly. I'm guessing IE is throwing a 404. Quote Link to comment https://forums.phpfreaks.com/topic/155512-ie-cannot-display-the-web-page/#findComment-818349 Share on other sites More sharing options...
mrMarcus Posted April 24, 2009 Share Posted April 24, 2009 try using full URL's, ie. header("Location: http://www.yoursite.com/path/to/file/if/applicable/bannertype.php?error=3"); instead of just bannertype.php?error=3 and so on for each header() function. just a thought. EDIT: also, what do the URL's look like out of the address bar in IE vs. Firefox .. are they the same or different? Quote Link to comment https://forums.phpfreaks.com/topic/155512-ie-cannot-display-the-web-page/#findComment-818353 Share on other sites More sharing options...
arcticfox Posted April 24, 2009 Author Share Posted April 24, 2009 Hi, Thanks for the fast reply. I removed the ?><?php part of the code and unfortunatly it still wont work, It's also worth mentoning that all the commands are executed (it uploads the file and updates my database) and if I removed the header code on certain bits I get the white screen instead of the error page. Any further advice would be appreciated Sorry for not using the code tags, I was in a bit of a rush. Thanks Arcticfox Quote Link to comment https://forums.phpfreaks.com/topic/155512-ie-cannot-display-the-web-page/#findComment-818354 Share on other sites More sharing options...
jonsjava Posted April 24, 2009 Share Posted April 24, 2009 did some minor cleanup on the script. Didn't see too much wrong (except the <?php ?> thing) <?php session_start(); if(!session_is_registered("myusername")){ header("location:login.php"); } // Check Type if ((isset($_POST) && $_POST['type'] == "News") ||(isset($_POST) && $_POST['type'] == "Main")){ $host= // Host name $username= // Mysql username $password= // Mysql password $db_name= // Database name // Connect to server and select databse. $connection = mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db($db_name, $connection)or die("cannot select DB"); // data sent from form $title=$_POST['title']; $type=$_POST['type']; $link=$_POST['link']; $summary=$_POST['summary']; $body=$_POST['body']; // To protect MySQL injection $title = stripslashes($title); $type = stripslashes($type); $link = stripslashes($link); $summary = stripslashes($summary); $body = stripslashes($body); $title = mysql_real_escape_string($title); $type = mysql_real_escape_string($type); $link = mysql_real_escape_string($link); $summary = mysql_real_escape_string($summary); $body = mysql_real_escape_string($body); // Test for null values if($title == "" || $summary == "" || $body == "" ){ mysql_close($connection); header("location:{$type}type.php?error=2"); exit; } else{ $sql="INSERT INTO `tblContent` (`title`, `summary`, `body`, `type`, `DateStamp`, `link`) VALUES ('$title', '$summary', '$body', '$type', NOW(), '$link');"; $result=mysql_query($sql); // Success = 1 if($result==1){ mysql_close($connection); header("location:content.php"); exit; } else { mysql_close($connection); header("location:{$type}type.php?error=1"); exit; } } }// END TYPE SET // Banner Type Set elseif($_POST['type'] == "Banner"){ // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { $host= // Host name $username= // Mysql username $password= // Mysql password $db_name= // Database name // Connect to server and select databse. $connection = mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // data sent from form $title=$_POST['title']; $type=$_POST['type']; $link=$_POST['link']; // To protect MySQL injection $title = stripslashes($title); $type = stripslashes($type); $link = stripslashes($link); $title = mysql_real_escape_string($title); $type = mysql_real_escape_string($type); $link = mysql_real_escape_string($link); // Test for null values if($title == "" || $type == "" || $link == "" ){ mysql_close($connection); header("location:bannertype.php?error=2"); exit; } else{ $sql="insert into tblContent (title, type, DateStamp, link, filename) values ('$title', '$type', NOW(), '$link', '".basename( $_FILES['uploadedfile']['name'])."')"; $result=mysql_query($sql); // Success = 1 if($result==1){ mysql_close($connection); header("location:content.php"); exit; } else { mysql_close($connection); header("location:bannertype.php?error=1"); exit; } } } // END UPLOAD IF // Error for file failure else{ header("location:bannertype.php?error=3"); exit;} } // END TYPE SET else{ echo "Error: No Type Was Defined!"; exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/155512-ie-cannot-display-the-web-page/#findComment-818380 Share on other sites More sharing options...
arcticfox Posted April 24, 2009 Author Share Posted April 24, 2009 Thanks for the response and help guys, I think i've narrowed it down a bit. If I remove the following code from the page holding the form all the header code works in IE and FF but my files are not uploaded. enctype="multipart/form-data" Heres the form code I use: <?php session_start(); if(!session_is_registered("myusername")){ header("location:login.php"); } ?> <html> <head> <title>Demo for PHP Forums</title> <link rel='stylesheet' href='scripts/main.css' type='text/css'/> <!-- TinyMCE --> <script type="text/javascript" src="scripts/tiny_mce/tiny_mce.js"></script> <script type="text/javascript"> tinyMCE.init({ mode : "textareas", theme : "simple" }); </script> <!-- /TinyMCE --> </head> <body> <div align="center" width="800px"> <table class="main" width="800px" border="0" > <tr><td> <!-- Header --> <?php include 'includes/header.inc.php'; ?> <!-- End Header --> </td></tr><tr><td> <!-- Top Navigation Bar --> <?php include 'includes/status.inc.php'; ?> <!-- End Top Navigation Bar --> </td></tr><tr><td height="430px"> <!-- Main Box --> <table align="center" border="0"> <form enctype="multipart/form-data" method="post" action="addcontent.php"> <tr> <td><?php if(isset($_GET['error']) AND $_GET['error'] == 2) {echo "<font color='Red'>*</font>";} ?> Title:</td><td><input name="title" id="title" size="66" /></td></tr><tr> <td>Type:</td><td><input name="type" id="type" value="Banner" readonly="readonly" /> <font color="red">Note: 500kb Maximum File Size</font></td></tr><tr> <td><?php if(isset($_GET['error']) AND $_GET['error'] == 2) {echo "<font color='Red'>*</font>";} ?> Link:</td><td><input name="link" id="link" size="66" /></td></tr><tr> <td>Choose a file to upload:</td><td><input name="uploadedfile" type="file" size="54" /></td></tr> <td colspan="2" align="right"><input type="submit" value="Add Content" /></td></tr> </form> </table> <br/> <?php echo "<div align='center'>"; if(isset($_GET['error']) AND $_GET['error'] == 1) {echo "<font color='Red'>The was an error adding your content.</font>";} if(isset($_GET['error']) AND $_GET['error'] == 2) {echo "<font color='Red'>Please Complete Required Fields *</font>";} if(isset($_GET['error']) AND $_GET['error'] == 3) {echo "<font color='Red'>File Upload Error, Please Try Again</font>";} echo "</div><br/>" ?> <!-- End Main Box --> </td></tr><tr><td> <!-- Footer --> <?php include 'includes/footer.inc.php'; ?> <!-- End Footer --> </td></tr> </table> </div> </body> </html> Thanks in advance for any help you can give me. Arcticfox Quote Link to comment https://forums.phpfreaks.com/topic/155512-ie-cannot-display-the-web-page/#findComment-818503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.