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 ------- $...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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/ |
|
|||
|
--- 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 |
|
|||
|
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 |
|
|||
|
--- 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 |
|
|||
|
> 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 ########################## |
|
|||
|
--- 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 |