473,836 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Redirect after running PHP script

15 New Member
Ok this is the script that handles the form submission and input's it to the SQL database. It works 100%.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con = mysql_connect("*****","*****","*****");
  3. if (!$con)
  4.   {
  5.   die('Could not connect: ' . mysql_error());
  6.   }
  7. mysql_select_db("ccsdesig_first", $con);
  8. $sql="INSERT INTO ***** (Name,Surname,Number,Email,MovingFrom,MovingTo,Date) 
  9.         VALUES ('$_POST[Name]','$_POST[Surname]','$_POST[Number]','$_POST[email]','$_POST[MovingFrom]','$_POST[MovingTo]','$_POST[Date]')";
  10.  
  11. $sql="INSERT INTO destination (CurrentPremises,CurrentFloor,DestinationPremises,DestinationFloor,WrapEverything,Unpack,Hangerpack,SendMaterials,InsureEverything) 
  12.         VALUES ('$_POST[CurrentPremises]','$_POST[CurrentFloor]','$_POST[DestinationPremises]','$_POST[CurrentFloor]','$_POST[WrapEverything]','$_POST[Unpack]','$_POST[Hangerpack]','$_POST[SendMaterials]','$_POST[InsureEverything]')";
  13.  
  14. if (!mysql_query($sql,$con))
  15.   {
  16.   die('Error: ' . mysql_error());
  17.   }
  18. mysql_close($con)
  19.   echo "Done";
  20. ?>
  21.  
What I would now like the script to do is to send the user to another page - what do I use to automatically redirect?
I've tried:
Expand|Select|Wrap|Line Numbers
  1. header("Location:http://www.xxxxxxx.com/viewguestbook2.php");
  2.  
and
Expand|Select|Wrap|Line Numbers
  1. <META HTTP-EQUIV="refresh" content="0;URL=index.php">
  2.  
And neither works - could someone point me in the right direction please?

My thanks in anticipation
Apr 20 '10
16 6466
Atli
5,058 Recognized Expert Expert
If you are getting that error, something is being printed before the header() call.

This is usually caused by white-spaces or other junk before the <?php block, BOM chars in Unicode documents or random echos in the code. - Check the source in the browser. That should include the junk chars that are causing this. (Post it here if you want us to take a look at it.)

You can also read this article for more details about this error, and how to fix it.
Apr 20 '10 #11
CalvinSmith
15 New Member
I read the article - thank you.
As far as I can see I have removed all the white spaces. Below is the code - Pls can you check where I have gone wrong:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con = mysql_connect("*","*","*");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7. mysql_select_db("*", $con);
  8. $sql="INSERT INTO contactdetails (Name,Surname,Number,Email,MovingFrom,MovingTo,Date)
  9. VALUES ('$_POST[Name]','$_POST[Surname]','$_POST[Number]','$_POST[email]','$_POST[MovingFrom]','$_POST[MovingTo]','$_POST[Date]')";
  10. $sql="INSERT INTO destination (CurrentPremises,CurrentFloor,DestinationPremises,DestinationFloor,WrapEverything,Unpack,Hangerpack,SendMaterials,InsureEverything) 
  11. VALUES ('$_POST[CurrentPremises]','$_POST[CurrentFloor]','$_POST[DestinationPremises]','$_POST[CurrentFloor]','$_POST[WrapEverything]','$_POST[Unpack]','$_POST[Hangerpack]','$_POST[SendMaterials]','$_POST[InsureEverything]')";
  12. if (!mysql_query($sql,$con))
  13. {
  14. die('Error: ' . mysql_error());
  15. }
  16. mysql_close($con);
  17. header("Location: http://www.*.co.za/email.php");
  18. exit;
  19. ?>
  20.  
Apr 21 '10 #12
Atli
5,058 Recognized Expert Expert
We aren't talking about white-spaces inside the <?php .. ?> blocks, but outside them. White-spaces inside them don't matter.

Expand|Select|Wrap|Line Numbers
  1.    <?php
  2. // There are three white-spaces before the <?php tag 
  3. // above this comment. This will cause the error.
  4.  
  5.    $variable = '
  6.         something
  7.         something else.';
  8. // The white-spaces in the above variable,
  9. // or the string, have no effect.
  10. ?>
Did you check out the source of the page in your browser? How did it look like?
Apr 21 '10 #13
CalvinSmith
15 New Member
Understood and as you can see there are no white spaces in the code I posted. I dont know how to view a PHP files source without it actually processing the script first. Once it processes the script the source is the following:
Expand|Select|Wrap|Line Numbers
  1. <br /> 
  2. <b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/ccsdesig/public_html/insert.php:1) in <b>/home/ccsdesig/public_html/insert.php</b> on line <b>17</b><br /> 
  3.  
If I open the PHP with notepad the source looks exactly the same as it does in expression web and as I posted above.
Apr 21 '10 #14
Atli
5,058 Recognized Expert Expert
Ok. The error still points to line #1 of the file, saying the output is starting there.

I would guess that your IDE is adding a BOM to your document; a Unicode special character that is meant to tell how the Unicode chars in the document are structured.

To check and fix that, you need an editor that can re-encode the file. I've used Notepad++ for that in the past. It's a very small and simple editor. A sort of advanced version of Notepad.

You can open your document in there, select "Encoding > Encode in UTF-8 without BOM", and then save the file.

That might fix the error.
Apr 21 '10 #15
CalvinSmith
15 New Member
The encoding resolved it!
Thank you!
Apr 21 '10 #16
Atli
5,058 Recognized Expert Expert
No problem. Glad it worked out :)
Apr 21 '10 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2311
by: Sentinel | last post by:
here is the entire thread From: "Kimmo Laine" <eternal.erectionN0.5P@Mgmail.com> Subject: Re: script in body Date: Mon, 20 Jun 2005 17:46:28 +0300 Message-ID: <d96klv$8vi$1@phys-news1.kolumbus.fi> Lines: 64 "Sentinel" <support@elma.hr> kirjoitti
2
5024
by: T Conti | last post by:
Howdy: I have converted a huge ASP page over to .Net (C#). The old page has been will be removed from our site, but I need to have a dummy page there that will redirect the user to the new site for backwards compatability. I originally used a Response.redirect but we found that users with high security settings get security pop-ups. We really don't want this. Here is the really basic page that I wrote to redirect the user to the new...
7
1924
by: Noozer | last post by:
Is it possible to redirect a user to another web page using ASP code located in page body? I have some ASP code that runs after generating some output to the browser. It checks for a condition that can only be calculated using the values produced in the output, so redirecting the user before the <html> tag isn't possible without running the code twice (which I'd like to avoid.) - so RESPONSE.REDIRECT "url" won't work. Any suggestions?
0
1369
by: SiteTamer | last post by:
I have a script that redirects to a file for downloading. Everything works fine EXCEPT: if the target of the redirect is type video/mpeg (extension .mpeg or .mpg), instead of prompting for download or open, IE opens a new browser window and displays garbage. I've only been able to reproduce the behavior in IE 6 running on Windows XP Professional. Everything works fine in Win2k Pro and Win2K Server (only systems tested so far). For an...
1
3910
by: Drebin | last post by:
I posted this over at the ASP.NET group, but you guys are pretty sharp - is this an obvious answer for anyone?? I'm really jammed up!! --------------------------------------- I am retrofitting a central login application and want to be able to read the Request.ServerVariables so that when they have logged on, I can send them back to wherever they were trying to go.. If you try to load a legacy ASP app, I do this:
15
15456
by: Drebin | last post by:
I am retrofitting a central login application and want to be able to read the Request.ServerVariables so that when they have logged on, I can send them back to wherever they were trying to go.. If you try to load a legacy ASP app, I do this: If Len(SessionID) <> 40 Then Response.Redirect "/WAS/Default.aspx?AppCode=2400" End If
5
7596
by: Josselin | last post by:
I have a page 'pni.php' to which paypal is redirecting after payment thsi page contains a db update script, no problem it's running well but once this script is executed (transparently for the use, as there is nothing to display) how can I redirect to another page ? header redirect can only be placed at the beginning of the page... not at the end I've already writen redirection but only when there was a form inside
4
970
by: Dave | last post by:
Is there a way to do a Response.Redirect and do a popup on the redirect?
5
4576
by: venner | last post by:
I'm having an issue with an ASP.NET website after upgrading to ASP.NET 2.0. The website makes use of a central authentication service (CAS) provided at the university I work for. Each page checks a session variable, and if it is not present, does a Response.Redirect to a webpage for the CAS passing a url parameter for the url to post back to. The CAS provides a page for the user to log into, validates the username and password, and then...
1
7300
by: gnawz | last post by:
Hi guys, I have a couple of php files that perform various tasks. I will use fields in my system and provide code as well I need help as follows: My database contains the fields Category and Brand I need to make some changes on a a number of brands in a Category
0
9818
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9668
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9374
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5649
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.