Jump to content


Photo

Loading new file via php as result condition check


  • Please log in to reply
4 replies to this topic

#1 stefands

stefands
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 28 October 2006 - 04:05 PM

Hello,

I'd like to open a new php document as the result of a condition check (if/elseif statement). If certain criteria apply during the execution of a search, then a specific file should be loaded. Vars don't need to be passed, no database action needed.
I tried an echo of the following code, which obviously didn't work  :P ::)
(just showing the basic html here!)
<HTML>
<HEAD>
<NOSCRIPT>
<META http-equiv="Refresh" content="0; URL=http://www.mysite.com/noresult.php">
</NOSCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

:-\
.:: who decides reason? .:...

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 28 October 2006 - 04:15 PM

...as in, go to another page, or including the file? be more specific. here are some examples:

$blah = 1;
if ($blah == 1) {
   // example 1: redirect to new page
   header('Location: newpage.php'); exit;

   // example 2: include the script
   include('somepage.php');
} else {
   // condition was false. spit out error or access denied or stick your tongue out at them
}


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 stefands

stefands
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 28 October 2006 - 07:47 PM

$blah = 1;
if ($blah == 1) {
   // example 1: redirect to new page
   header('Location: newpage.php'); exit;

The redirect doesn't work.
How can I break out of an if/elseif statement and go to an other page?

.:: who decides reason? .:...

#4 stefands

stefands
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 01 November 2006 - 02:05 PM

I've read the sticky, other posts concerning this issue, etc.
I'm passed the "header already sent" warnings and all that... but the redirect still doesn't work.
The php code is above my <html>, checked if the condition statement is true etc? Any advise?

$total = 0
if ($total = 0){
header("Location: newsearch.php");
}

.:: who decides reason? .:...

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 November 2006 - 06:53 PM

$total = 0;
if ($total == 0){
header("Location: newsearch.php"); exit;
}

- you forgot a ; to terminate your first expression.
- you used = instead of == in your condition.  = is the assignment operator, == is the equality operator.
- you need to add exit; after a header call when you redirect, to keep any further script from being executed.
- make sure that newsearch.php is named right, in the right directory (as shown, it should be in the same directory as this script
- still not working after all that? check to make sure this code isn't wrapped inside some other condition that is evaluating false.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users