PHP Returning False Before Being Ran -
In my PHP program, I have 2 radio buttons and submit buttons. I button 1 = EST button echo 2 = PST echo The thing that works fine is that, before choosing an alternative to me, my wrong values are already echoing. How do I get the script after clicking submit button? (Code below);
& lt ;? Php if (isset ($ _ POST ['EST'])) {date_default_timezone_set ('America / New_york'); $ Today = Date ("F, LJS YG: I: SA"); Echo today $; } And if (isset ($ _ POST ['PST'])) {date_default_timezone_set ('America / Los_Angeles'); $ Today = Date ("F, LJS YG: I: SA"); Echo today $; } Else {echo 'Select an option!'; }? & Gt; & Lt; Form action = "index.php" method = "post" & gt; Choose your time zone: & lt; Br / & gt; EST: & lt; Input type = "radio" name = "EST" /> PST: & lt; Input type = "radio" name = "PST" /> & Lt; Br / & gt; & Lt; / Br & gt; & Lt; Input type = "submit" value = "submit!" Name = "submit" /> & Lt; / Form & gt;
You have two options here, you either have a full PHP block << Strong> or You can submit your form to a separate script for the form.
Method 1 if (isset ($ _ POST ['submit']) {/ Submit / Submit button (and full form), continue: if (isset ($ _ POST ['EST'])) {date_default_timezone_set ('America / New_york'); $ Today = Date ("F, LJS YG: I: SA"); Echo today $; } And if (isset ($ _ POST ['PST'])) {date_default_timezone_set ('America / Los_Angeles'); $ Today = Date ("F, LJS YG: I: SA"); Echo today $; } Else {echo 'Select an option!'; }} // form goes here method 2 form.html < Pre> & lt; Form action = "submit.php" method = "post" & gt; Choose your time zone: & lt; Br / & gt; EST: & lt; Input type = "radio" name = "EST" /> PST: & lt; Input type = "radio" name = "PST" /> & Lt; Br / & gt; & Lt; / Br & gt; & Lt; Input type = "submit" value = "submit!" Name = "submit" /> & Lt; / Form & gt; submit.php & lt ;? Php if (isset ($ _ POST ['EST'])) {date_default_timezone_set ('America / New_York'); $ Today = Date ("F, LJS YG: I: SA"); Echo today $; } And if (isset ($ _ POST ['PST'])) {date_default_timezone_set ('America / Los_Angeles'); $ Today = Date ("F, LJS YG: I: SA"); Echo today $; } Else {echo 'Select an option!'; }
Comments
Post a Comment