Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I make a script open in a new page

Status
Not open for further replies.

judi

Programmer
Jan 13, 2001
35
US
I am using an include to go to different PHP scripts. All of them open into a new page except for one. I can't for the life of me figure out why this one insists on appending the script to the previous script. Here is my code for the switch script:

switch($submitter)
{

case "Shop Some More":
{
include("displaycategories.php");
break;
}

case "Checkout":
{
include("customer.php");
break;
}

case "Update":
{
include("ShoppingCart.php");
break;
}

case "Cancel":
{
include("displaycategories.php");
break;
}
case "Email and call 800 number":
{
include("customer.php");
break;
}
case "Email your order":
{
include("customer.php");
break;
}
case "Use PayPal":
{
include("customerpaypal.php");
break;
}
case "Continue Checkout":
{
If ($EmailDone == 1){
include("GoToPayPal.php");
break;
}
else {
include("customerpaypal.php");
break;
}
}

default:
{
include("customer.php");
break;
}
} // end switch


This script is the only one appending on the previous one:
include("GoToPayPal.php"); And I know it goes there because the button does display but it displays on the end of another script.


Here is the code for GoToPayPal.php such as it is right now:

<?php
session_start();

?>

<HTML>
<HEAD>
<TITLE>Landscape Light Checkout Form</TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="style1.css">
</HEAD>
<BODY>
<form action=" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="bufo@emailaccount.com">
<input type="hidden" name="item_name" value="Landscape Lighting Order">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="amount" value=<?PHP echo($total) ?>>
<input type="image" src=" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
</BODY>
</HTML>

Any ideas would be appreciated,
judi
 
What do you exactly mean when you say it's "appending" to the previous script?
 
I am using an include to go to different PHP scripts.

Why would you use include to go to a script? include is to include a script in this one (if you know what i mean).
 
Yes, I remember what an include does from C. But that's the only way I know to use more then one submit button to go to different scripts. In my form action, I have it going to the switch script and based on the value of the submit button, I send it to the appropriate script. This works perfectly except for here.

Here it just takes that new button from my GoToPayPal script and appends it to the script that was previously displayed. I want that button to be on a blank page. I have more to add obviously, but right now, I'm stuck on that.

If you have a better idea then using include, please let me know.

Thanks for all your help.
 
I know what you're doing, since I've done similar code, except all of my code is in-line. The only time I use includes is when the included file is going to be used by more than one source file.

Now to your problem. I don't know if an include can be used with an IF. That might be the cause of your problem. Having your code in-line would alleviate that issue.

One comment on your coding style. Lose the "{" and "}" in your "case" statements. They are not needed and just clutter the code.

A switch block should look something like:
Code:
switch ($variable) {
   case 'test1':
      code line 1;
      code line 2;
      break;
   case 'test2':
      code line 3;
         .....
      break;
   default:
      default code;
}
Note that the default area is not needed.

Ken
 
More questions/comments:

1. Is there any HTML output before the include is called?
2. In this case you do not want to "include" the file, you want to redirect the browser to a new page. Use the header() directive:
Code:
 case "Use PayPal":
   {
      header("Location: customerpaypal.php");
      exit;
   }
Be careful that you might have to insert the correct path before the script that it redirects to.
 
kenrbnsn, what do you use instead of include? What I wouldn't give for a goto or a BAS. LOL

I lost the {} and am no longer using an if and it still appends the button to the previous script.

DRJ478, the redirect didnt do anything.

 
If the redirect didn't do anything then the script does not get to it. Even if the header fails (which I believe to be impossible) the script would have stopped. Did you put it into the appropriate place?
 
It does get to it because the other option would show error messages and it does. Here is the code I used:

case ("Continue Checkout") && ($EmailDone == 1):
header("Location: GoToPayPal.php");
exit;

I also put in an echo there with a msg and it does display that. So it's getting to that code.
 
Unfortunately this doesn't make much sense - probably your error reporting is set to suppress most warnings.
However, it seems that you output something before the include/redirect.
Wouldn't that explain that the button appears at the end of the previously sent output?
 
Well, I output something before I go to the switch.php. But once it's there, all it does is go through that case statement. I've taken out all displays. The only other thing the switch script does is start a session.
 
I output something before I go to the switch.php

only other thing the switch script does is start a session

Are you starting the session before or after you produce output? Unless you're using output buffering, you'll have to start the session before you produce any output.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I start a session at the beginning of each script.

This is how it works:

It goes to a page (customerpaypal.php) that displays their shopping cart and a form for them to fill out. They have the choices of clicking on a Continue Checkout button or a Shop Some More button.

It goes to switch.php to see which button they clicked. If it is the Continue Checkout, it goes back to (customerpaypal.php) and error checks the form. If the form has errors, it will display the errors.

If there are no errors, it sends an email, sets a flag and does an include back to switch program.

In the switch program, if the flag is true and the submitter still equals Continue Checkout (which it does) then it needs to go to another program which displays the paypal button.

My problem exists because if the form is correctly filled in, I want it to not only send an email but go to another screen.
 
are you sure that your $submitter var always has the value that u expect
 
It goes to switch.php
You mean the form posts to switch.php?

An include does not really "go" anywhere, it just loads the code from that file into the spot where the include statement is in the calling script. It's like assembling a puzzle from referenced pieces.

Pls. tell me if I'm reading your message correctly:
1. customerpaypal.php POSTS to switch.php
2. If the continue checkout button was posted it redirects(how?) to customerpaypal.php again [maybe you include it].
3. The redirect/inclusion draws the page and validates the input.
4. If errors, they are displayed and execution is terminated.
5. No errors, send mail [I assume it sends mail successfully] and display the GoToPayPal.php

Now, here's the real deal:
You cannot send a header() after something has been sent to the browser. It has to be the first thing. When you use session_start() you have to use it first since it sends a session_chache_limiter header to the browser.
If you output anything between that and the redirection header it will fail. headers have to be the first thing to be sent.

Turn output buffering on when you return from switch.php so the output goes into a buffer, not the browser. If there are no errors detected send the mail and redirect. The buffer can be abandoned.
Only dump out the buffered HTML when you detected errors and an error display is necessary.
That's how I understand it from your posts.
 
Judi,

You asked what I use instead of includes, I usually just type my code in the source file. The general structure of most of my PHP code these days is as follows:
Code:
<?
// initialization code 
// error checking
// functions
?>
<DOCTYPE ...>
<html>
<head>
<title>...</title>
... Style sheet links ... Javascript ... META statements
</head>
<body>
... any static HTML code that's the same for all invocations ...
<? switch ($var) {
   case 1:
// PHP statements ... ?>
... HTML statements ...
<? break;
   case 2:
...
...
... etc ...
...
...
   break;
} /* end of switch */
?>
</body>
</html>

One drawback to this method is that the source file does tend to grow.

You can see this technique in operation at
Ken
 
ascikey - yes, I'm positive my submitter is correct. BTW, love your alias. Did you know the guy who wrote ASCII just died?

DRJ478 I do my session_start() at the beginning of every script. I don't know how I can apply the output buffering to my program. It sends the email just fine. My case statement in my switch program works perfectly in all the other cases. When it includes another script, it goes there and gives it a new page. It's just this one. I don't like using includes, but I can't think of another way to do this. I'm obviously missing something so minor. I'm used to coding in VB and have done Assembly Language, but this has got me stumped.

kenrbnsn - I'm not sure I understand what you're doing.

Thanks all for putting up with me. This shouldn't be that difficult for me. Maybe I'm just getting dense in my old age.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top