I've been trying to work with PHP lately, and while I thought that I understood it, when it looks like either my if or echo statements aren't working. I've inserted the following code into an HTML file:
<!DOCTYPE html><html><body><form> <fieldset> <legend>Organization XIII</legend> Nobody: <select name="nobody"> <optgroup label="Founding members"> <option value="I">Xemnas</option> <option value="II">Xigbar</option> <option value="III">Xaldin</option> <option value="IV">Vexen</option> <option value="V">Lexaeus</option> <option value="VI">Zexion</option> </optgroup> <optgroup label="Other"> <option value="VII">Axel</option> <option value="VIII">Saïx</option> <option value="IX">Demyx</option> <option value="X">Luxord</option> <option value="XI">Marluxia</option> <option value="XII">Larxene</option> <option value="XIII">Roxas</option> </optgroup> </select> <br /> Somebody: <select name="somebody"> <optgroup label="Apprentices"> <option value="I">Xehanort</option> <option value="II">Braig</option> <option value="III">Dilan</option> <option value="IV">Even</option> <option value="V">Aeleus</option> <option value="VI">Ienzo</option> </optgroup> <optgroup label="Other"> <option value="VII">Lea</option> <option value="VIII">Isa</option> <option value="IX">???</option> <option value="X">???</option> <option value="XI">???</option> <option value="XII">???</option> <option value="XIII">Sora</option> </optgroup> </select> <br /> <input type=submit></input> <?php if ($_REQUEST['nobody']) == ($_REQUEST['somebody']) { echo "Correct"; } else { echo "Incorrect"; }?> </fieldset> </form> </body> </html>
Can anyone tell me what's not working, and how to fix it?
Offline
I replied on the CS topic.
Offline
I know. The forums were down at the time, so I posted here.
Offline
@TRocket Yep
@OP Some of your syntax is wrong.
so try this:
<?php if ($_POST['nobody'] === $_POST['somebody']) { echo "Correct"; } else { echo "Incorrect"; } ?>
And Change
<form>
to
<form action="" name="myform" method="post">
Offline
If you use method='POST', then use $_POST. If you use method='GET' then use $_GET.
Never heard of $_REQUEST
Offline
Zeusking19 wrote:
If you use method='POST', then use $_POST. If you use method='GET' then use $_GET.
Never heard of $_REQUEST
$_REQUEST has variables from both GET and POST.
Offline
Um, okay, I've switched it to:
<!DOCTYPE html><html><form action="" name="my form" method="post"> <fieldset> <legend>Organization XIII</legend> Nobody: <select name="nobody"> <optgroup label="Founding members"> <option value="I">Xemnas</option> <option value="II">Xigbar</option> <option value="III">Xaldin</option> <option value="IV">Vexen</option> <option value="V">Lexaeus</option> <option value="VI">Zexion</option> </optgroup> <optgroup label="Other"> <option value="VII">Axel</option> <option value="VIII">Saïx</option> <option value="IX">Demyx</option> <option value="X">Luxord</option> <option value="XI">Marluxia</option> <option value="XII">Larxene</option> <option value="XIII">Roxas</option> </optgroup> </select> <br /> Somebody: <select name="somebody"> <optgroup label="Apprentices"> <option value="I">Xehanort</option> <option value="II">Braig</option> <option value="III">Dilan</option> <option value="IV">Even</option> <option value="V">Aeleus</option> <option value="VI">Ienzo</option> </optgroup> <optgroup label="Other"> <option value="VII">Lea</option> <option value="VIII">Isa</option> <option value="IX">???</option> <option value="X">???</option> <option value="XI">???</option> <option value="XII">???</option> <option value="XIII">Sora</option> </optgroup> </select> <br /> <input type=submit></input> <?php if ($_POST['nobody']) === ($_POST['somebody']) { echo "Correct"; } else { echo "Incorrect"; }?> </fieldset> </form> </body</html>
Still nothing's happening when I click Submit nothing happens other than the added ?nobody=I&somebody=I to the URL.
Offline
You said it was an HTML document...change the extension to PHP.
Offline
You have </body</html> (not </body></html>) at the end. Also, did you put it on a server yet?
Offline
scimonster wrote:
You have </body</html> (not </body></html>) at the end. Also, did you put it on a server yet?
Oh, I just added that part myself. There's a lot of other HTML in it that I didn't put in, so I just typed the doctype, body, and html tags myself. Also, I haven't.
Last edited by maxskywalker (2012-03-01 10:29:47)
Offline
Well, PHP will not work if it's not run on a server.
Offline