Solved

header not working but worked in wampserver

Posted on 2014-01-20
15
626 Views
Last Modified: 2014-01-21
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
Comment
Question by:JCWEBHOST
  • 9
  • 5
15 Comments
 
LVL 18

Expert Comment

by:Matthew Kelly
ID: 39794220
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39794291
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
 

Author Comment

by:JCWEBHOST
ID: 39796099
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
 

Author Comment

by:JCWEBHOST
ID: 39796117
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39796365
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
 

Author Comment

by:JCWEBHOST
ID: 39796394
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39796523
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:JCWEBHOST
ID: 39796552
0
 

Author Comment

by:JCWEBHOST
ID: 39796578
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
 

Author Comment

by:JCWEBHOST
ID: 39796825
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
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39796898
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
 

Author Comment

by:JCWEBHOST
ID: 39796929
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
 

Author Comment

by:JCWEBHOST
ID: 39796934
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
 

Author Closing Comment

by:JCWEBHOST
ID: 39796935
give you additional knowledge if you are new to php. topz ray
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39796939
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now