Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 677
  • Last Modified:

header not working but worked in wampserver

please help me make the header work, everything is working the way it should, but my header is not working... it was working on the wamp server, but  now im on a windows server, and its not working.. is they some difference between the servers?
wampsrv.txt
0
JCWEBHOST
Asked:
JCWEBHOST
  • 9
  • 5
1 Solution
 
Matthew KellyCommented:
Are you getting an error like "Warning: Cannot modify header information"?

Your test script that you uploaded here worked on my test server; but header() needs to be called before any output is called so you would need to move your php code in front of the html rending as shown below:

See documentation here: http://www.php.net/manual/en/function.header.php

<?php
         
		 include("config.php");
		
		 if(isset($_POST['submitcat']))
		 {

	         $catname = strip_tags($_POST['catname']);
	         $myresult= mysql_query("insert into cat values('','".$catname."')");
	
         if($myresult){
	            header ('location:display-cat.php');
	            
	            }

                   		  
     else{
	  echo "Not Uploaded";}
       }
	
	
	?>

<html>
 <head>
  <title>Add New Category</title>
  <script src="js/jquery.js"></script>	
  <script src="js/script.js"></script>	
  <script src="js/jquery-ui-1.8.17.custom.min.js"></script>	
  <link rel="stylesheet" href="css/style.css">
 </head>
 <body>	
			<form enctype="multipart/form-data"  method="post" action=""> 
		<table width="100%" border="0" cellpadding="4" cellspacing="0">
			<tr>
				<td colspan="2" align="right"><a href="display-cat.php" id="close">Close</a></td>
			</tr>
			<tr>
				<td>Category</td>
				<td><input type="text" name="catname"></td>
			</tr>
		
			<tr>
				<td align="right"></td>
				<td><input type="submit" name="submitcat" value="Save"><input onclick="location.href='display-cat.php' ;" type="button" value="cancel"></td>
			</tr>
		</table>
		</form>
	
</body>
</html>

Open in new window

0
 
Ray PaseurCommented:
is not working
As far as I can recall, this is not one of the known error messages.  Please take a moment to learn about the SSCCE, then post the test sample here along with the exact text of any error messages and the link to the public-facing script that demonstrates the error.  Once we can see that we will be able to offer much better help!
0
 
JCWEBHOSTAuthor Commented:
matthew kelly,  my code doesn't give any errors, and i just did it how you wanted me to do it, and it still does the same thing, it doesn't wanna redirect me "the header doen't work"..  when i tested it on wamp sever it works. but on the windows server it doesn't, is they a difference in servers.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JCWEBHOSTAuthor Commented:
ray paseur... here are my very simply codes, the first one, i test if im  assessing the 'if'  statement which echoes "im here" (and it does work, it prints on the screen), the second test, i replace it with with a header... no error is given, im still not redirected... what could be the issue?
testcode1.txt
testcode2.txt
0
 
Ray PaseurCommented:
We might have a better chance of helping you if you can help us.  

Please post the link to the public-facing script that demonstrates the error.
Here are the scripts you posted, installed without any change on my server.  You can click the links to see what they do.  In short, they both work "correctly."  But that may not be the result you want.
http://www.laprbass.com/RAY_temp_jcwebhost_echo.php
http://www.laprbass.com/RAY_temp_jcwebhost_header.php

The test case does not illustrate any issue, hence it does not qualify as the SSCCE.  If you're new to PHP programming and want to get a foundation in how all this stuff works, this article will help you get going in the right direction.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

Perhaps you have a script named /display-cat.php and it is failing without any output?  This is the sort of thing that we could see when we see your SSCCE.

You can discern differences in PHP installations (there are about a zillion configuration variables that are stumbling blocks) by running this little script, shown here in its entirety.  You probably want to look for every option that contains the substring "error" so you can find out why you're not getting any error information from the windows server.
<?php phpinfo();

Open in new window

I'd like to help you but without any visibility into your installation and code base, about all I can do is show you what your code does on a properly configured PHP installation.  The header() redirects, but to a page I do not have installed.
0
 
JCWEBHOSTAuthor Commented:
my display-cat, display all the records that i have added in the add-cat.php. i can only view them when i click cancel on the add-cat.php...

so what you trying to say is, they are difference in php installations???
0
 
Ray PaseurCommented:
There are many differences in PHP installations, but (except for error reporting settings) that is beside the point.  What I am trying to say is that we need to see the SSCCE.  

There is a reason why I keep saying SSCCE.  

We can't fix the problem from your description of the problem.  We only have a chance of helping with something like this if we can the true, correct and complete example that illustrates the problem.  That means you need to set up the test cases on your server and post the links here.
0
 
JCWEBHOSTAuthor Commented:
i read the ccsse doc, i cut out some pieces of code and even added some dummy values on the form...

i believe this is a CCSSE...???

<?php
							          include("config.php");

							
										 if(isset($_POST['submitcat']))
										 {
								
									         $catname = strip_tags($_POST['catname']);
									         $myresult= mysql_query("insert into cat values('','".$catname."')");
									
								         if($myresult){
								                    header ('location:display-cat.php');
								                    }
										  
								     else{
									  echo "Not Uploaded";}
								       }
	
	
							  ?>
	                            
								   <form enctype="multipart/form-data"  method="post" action=""> 
										<table width="100%" border="0" cellpadding="4" cellspacing="0">
													<tr>
														<td colspan="2" align="right"><a href="display-cat.php" id="close">Close</a></td>
													</tr>
													<tr>
														<td>Category</td>
														<td><input type="text" name="catname"></td>
													</tr>
												
													<tr>
														<td align="right"></td>
														<td><input type="submit" name="submitcat" value="Save"><input onclick="location.href='display-cat.php' ;" type="button" value="cancel"></td>
													</tr>
										</table>
		                          </form>

Open in new window

Ed. Note: Moved code into Code snippet.
ssccefile.txt
0
 
JCWEBHOSTAuthor Commented:
i have solved the problem, by using javascript to redirect...  

this is the script i placed in between my if statement.

?> <script>
                   window.location.replace("http://google.com");
                   </script> <?php
0
 
Ray PaseurCommented:
I think you might get some value from this book.  There are many things wrong in that little script, and you almost certainly want to get it fixed up before hackers destroy your data base.  Get the latest edition, and when a new edition comes out, replace your copy and give the obsolete addition to one of your enemies.
http://www.amazon.com/PHP-MySQL-Web-Development-Edition/dp/0321833899

One of the things you're going to have to deal with is MySQL.  PHP is removing MySQL support soon, so you will want to make the move to one of the other database extensions.  This article will help you with that part of things.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
 
JCWEBHOSTAuthor Commented:
tanx alot ray, they is alot i should still learn about the world of php. Php is deprecating MSQL, wow! i didn't even know about that ... god bless ray.
0
 
JCWEBHOSTAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for JCWEBHOST's comment #a39796825

for the following reason:

an alternative to using the header() function, if it is not working in your server
0
 
JCWEBHOSTAuthor Commented:
give you additional knowledge if you are new to php. topz ray
0
 
Ray PaseurCommented:
Thanks!  If you want some other good learning resources, this article may help:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now