RE: function help redirect help

This is a discussion on RE: function help redirect help within the PHP General forums, part of the PHP Programming Forums category; Here is what Ihave I am getting a elseif parse error. Is there something I'm leaving out? Frank code ------- $...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-27-2003
Frank Tudor
 
Posts: n/a
Default RE: function help redirect help

Here is what Ihave

I am getting a elseif parse error. Is there something I'm
leaving out?

Frank

code
-------

$payment = "1";

function payment(){
global $payment;
if ($payment == "0");
header ("location:test_page.html");
}
global $payment;
elseif ($payment == "1") {
header ("location:test_page2.html");
}

__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
Reply With Quote
  #2 (permalink)  
Old 10-27-2003
Chris Shiflett
 
Posts: n/a
Default Re: [PHP] RE: function help redirect help

--- Frank Tudor <frank_tudor@yahoo.com> wrote:
> I am getting a elseif parse error.


Let me clean up your code a bit, and hopefully the error will stand out.

function payment()
{
global $payment;
if ($payment == '0');
header ('Location: http://example.org/test_page.html');
}

global $payment;

elseif ($payment == '1')
{
header ('Location: http://example.org/test_page2.html');
}

Can you see the problem(s) now? Never underestimate the benefits of writing
clean code. :-)

Chris

=====
My Blog
http://shiflett.org/
HTTP Developer's Handbook
http://httphandbook.org/
RAMP Training Courses
http://www.nyphp.org/ramp
Reply With Quote
  #3 (permalink)  
Old 10-27-2003
Frank Tudor
 
Posts: n/a
Default Re: [PHP] RE: function help redirect help

I made the changes but I am getting:

Parse error: parse error, unexpected T_ELSEIF

I did take the second global statement out after I cut and
pasted your code and modified the urls

so now here is what it looks like (the whole thing).

Frank
--------

<?PHP
$payment = "1";



function payment()
{
global $payment;
if ($payment == '0');
header ('Location: http://ftudor/test/test_page.html');
}

elseif ($payment == '1')
{
header ('Location: http://ftudor/test/test_page2.html');
}



?>

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
Reply With Quote
  #4 (permalink)  
Old 10-27-2003
Chris Shiflett
 
Posts: n/a
Default Re: [PHP] RE: function help redirect help

--- Frank Tudor <frank_tudor@yahoo.com> wrote:
> function payment()
> {
> global $payment;
> if ($payment == '0');
> header ('Location: http://ftudor/test/test_page.html');
> }
>
> elseif ($payment == '1')
> {
> header ('Location: http://ftudor/test/test_page2.html');
> }


Your code looks cleaner, so now isn't the error very obvious?

It seems to me that you intended your first conditional statement to send the
Location header when true. Therefore, you did not mean to put a semicolon there
but rather a curly brace.

This is why your function ends prematurely (assuming you did not intend for it
to end there), and then you have an elseif statement dangling around with no
corresponding if.

Chris

=====
My Blog
http://shiflett.org/
HTTP Developer's Handbook
http://httphandbook.org/
RAMP Training Courses
http://www.nyphp.org/ramp
Reply With Quote
  #5 (permalink)  
Old 10-27-2003
Dvdmandt
 
Posts: n/a
Default Re: [PHP] RE: function help redirect help

> Can you see the problem(s) now? Never underestimate the benefits of
writing
> clean code. :-)


Hehe, you should see my code..

function dp_neg($v1,$v2){
$neg = ((substr((string)$v1,0,1)=="-")||((substr((string)$v2,0,1)=="-")));
$bneg= ((substr((string)$v1,0,1)=="-")&&((substr((string)$v2,0,1)=="-")));
if(!$bneg && $neg){
$tmp=$v1*$v2;
$tmp=(string)$tmp;
$an=str_replace("-","+",$tmp);
}
else{
$an="-".($v1*$v2);
}
return $an;
}
function xyz($f,$s){
$f=s_str($f);
$s=s_str($s);
$t=($f==$s)?$f:s_str($f.$s);
return $t;
}
function s_str($str)
{$l=strlen($str);for($x=0;$x<$l;$x++){$ar[]=$str{$x};}sort($ar);return
implode('',$ar);}
$e_a[0]=gs($e1);$e_a[1]=gs($e2);
$e_a[2]=gs($e3);$e_a[3]=gs($e4);
for($i=0;$i<4;$i++){
$t[$i]=split(":",$e_a[$i]);}
$r[0][0]=dp_neg($t[0][3],$t[2][3]);
$r[0][1]=xyz($t[0][2],$t[2][2]);
$r[1][0]=dp_neg($t[0][3],$t[3][3]);
$r[1][1]=xyz($t[0][2],$t[3][2]);
$r[2][0]=dp_neg($t[1][3],$t[2][3]);
$r[2][1]=xyz($t[1][2],$t[2][2]);
$r[3][0]=dp_neg($t[1][3],$t[3][3]);
$r[3][1]=xyz($t[1][2],$t[3][2]);
for($i=0;$i<4;$i++){
$exp .=
((substr($r[$i][0],0,1)=="-")?$r[$i][0].$r[$i][1]:($r[$i][0].$r[$i][1]))."
";}


No, that probably wont compile as that's only a little part of it, but still
a pretty easy part of it.. :)
--
// DvDmanDT
MSN: dvdmandt€hotmail.com
Mail: dvdmandt€telia.com
##########################
Please, if you are using windows, you may be infected by Swen. Please go
here to find out more:
http://us.mcafee.com/virusInfo/defau...er&hcName=swen
http://securityresponse.symantec.com...swen.a@mm.html
##########################
Reply With Quote
  #6 (permalink)  
Old 10-27-2003
Chris Shiflett
 
Posts: n/a
Default Re: [PHP] RE: function help redirect help

--- DvDmanDT <dvdmandt@telia.com> wrote:
> > Can you see the problem(s) now? Never underestimate the benefits of
> > writing clean code. :-)

>
> Hehe, you should see my code..


Yes, very messy and disorganized. Is this an admission of guilt, a cry for
help, or what?

Chris

=====
My Blog
http://shiflett.org/
HTTP Developer's Handbook
http://httphandbook.org/
RAMP Training Courses
http://www.nyphp.org/ramp
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:50 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0