473,700 Members | 2,801 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 #1
16 6457
chathura86
227 New Member
you can use a JS to redirect user

Regards
Apr 20 '10 #2
Atli
5,058 Recognized Expert Expert
Hey.

What happened when you tried the header() function? It should have worked.
(Try turning on the error messages to see what really happened.)

You can do three things to redirect a user:
  1. Send a Location header, using the header function. - This is the preferred method, as it is the "shortest" way to send the browser the request to relocate.
  2. Add a <meta> "refresh" header. - This is a close second, only because it requires the browser to parse the HTML before actually getting the request.
  3. Send a JavaScript "location.h ref" value. - This should be avoided, because JavaScript can not be counted on in all cases. Users can turn off JavaScript, and some browser (and I use that term loosely) don't support it.
Apr 20 '10 #3
CalvinSmith
15 New Member
somehow it posted twice
Apr 20 '10 #4
CalvinSmith
15 New Member
Hi,

I get the following error:
Parse error: syntax error, unexpected T_STRING in /home/****/public_html/insert.php on line 21
When using the following:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', true);
  4. $con = mysql_connect("localhost","*****","*****");
  5. if (!$con)
  6.   {
  7.   die('Could not connect: ' . mysql_error());
  8.   }
  9. mysql_select_db("*****", $con);
  10. $sql="INSERT INTO contactdetails (Name,Surname,Number,Email,MovingFrom,MovingTo,Date) 
  11.         VALUES ('$_POST[Name]','$_POST[Surname]','$_POST[Number]','$_POST[email]','$_POST[MovingFrom]','$_POST[MovingTo]','$_POST[Date]')";
  12.  
  13. $sql="INSERT INTO destination (CurrentPremises,CurrentFloor,DestinationPremises,DestinationFloor,WrapEverything,Unpack,Hangerpack,SendMaterials,InsureEverything) 
  14.         VALUES ('$_POST[CurrentPremises]','$_POST[CurrentFloor]','$_POST[DestinationPremises]','$_POST[CurrentFloor]','$_POST[WrapEverything]','$_POST[Unpack]','$_POST[Hangerpack]','$_POST[SendMaterials]','$_POST[InsureEverything]')";
  15.  
  16. if (!mysql_query($sql,$con))
  17.   {
  18.   die('Error: ' . mysql_error());
  19.   }
  20. mysql_close($con)
  21. header("Location: http://www.xxx.com/email.php");
  22. exit;
  23. ?>
  24.  
Apr 20 '10 #5
Atli
5,058 Recognized Expert Expert
You are missing the semi-colon (;) from line #20. All lines must end in a semi-colon.
Apr 20 '10 #6
CalvinSmith
15 New Member
@Atli
Warning: Cannot modify header information - headers already sent by (output started at /home/****/public_html/insert.php:1) in /home/****/public_html/insert.php on line 21
Apr 20 '10 #7
chathura86
227 New Member
you cannot have any echo statements or none php codes before the header

ie. you cannot send any output to the browser before header()

make sure that (even a white space could case an error)

Regards
Apr 20 '10 #8
CalvinSmith
15 New Member
Thanks for your reply.
I checked through the code and dont think anything is posting to the browser at all. Perhaps I have missed something though?
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', true);
  4. $con = mysql_connect("*","*","*");
  5. if (!$con)
  6.   {
  7.   die('Could not connect: ' . mysql_error());
  8.   }
  9. mysql_select_db("*", $con);
  10. $sql="INSERT INTO contactdetails (Name,Surname,Number,Email,MovingFrom,MovingTo,Date) 
  11.         VALUES ('$_POST[Name]','$_POST[Surname]','$_POST[Number]','$_POST[email]','$_POST[MovingFrom]','$_POST[MovingTo]','$_POST[Date]')";
  12. $sql="INSERT INTO destination (CurrentPremises,CurrentFloor,DestinationPremises,DestinationFloor,WrapEverything,Unpack,Hangerpack,SendMaterials,InsureEverything) 
  13.         VALUES ('$_POST[CurrentPremises]','$_POST[CurrentFloor]','$_POST[DestinationPremises]','$_POST[CurrentFloor]','$_POST[WrapEverything]','$_POST[Unpack]','$_POST[Hangerpack]','$_POST[SendMaterials]','$_POST[InsureEverything]')";
  14. if (!mysql_query($sql,$con))
  15.   {
  16.   die('Error: ' . mysql_error());
  17.   }
  18. mysql_close($con);
  19. header("Location: http://www.*.co.za/email.php");
  20. exit;
  21. ?>
  22.  
Apr 20 '10 #9
CalvinSmith
15 New Member
Warning: Cannot modify header information - headers already sent by (output started at /home/*/public_html/insert.php:1) in /home/*/public_html/insert.php on line 19
Apr 20 '10 #10

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

Similar topics

2
2306
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
5015
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
1917
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
1362
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
3903
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
15436
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
7579
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
4568
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
7291
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
8641
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
9203
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
9060
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8958
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8912
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
7797
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...
1
6557
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4396
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...
2
2379
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.