This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-02-29 10:41:06

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Bugged PHP

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:

Code:

<!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

 

#2 2012-02-29 12:08:13

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Bugged PHP

I replied on the CS topic.  smile

Offline

 

#3 2012-02-29 12:27:09

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Bugged PHP

I know.  The forums were down at the time, so I posted here.

Offline

 

#4 2012-02-29 13:01:52

TRocket
Scratcher
Registered: 2009-08-18
Posts: 1000+

Re: Bugged PHP

1.you need to specify a form type and action
2. use $_POST or $_GET not $_REQUEST


http://i.imgur.com/1QqnHxQ.png

Offline

 

#5 2012-02-29 13:45:12

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: Bugged PHP

@TRocket Yep

@OP Some of your syntax is wrong.
so try this:

Code:

<?php
if ($_POST['nobody'] === $_POST['somebody']) {
    echo "Correct";
}
else {
    echo "Incorrect";
}
?>

And Change

Code:

<form>

to

Code:

<form action="" name="myform" method="post">

http://i.imgur.com/zeIZW.png

Offline

 

#6 2012-02-29 14:11:46

Zeusking19
Scratcher
Registered: 2011-07-10
Posts: 1000+

Re: Bugged PHP

If you use method='POST', then use $_POST. If you use method='GET' then use $_GET.

Never heard of $_REQUEST


http://i49.tinypic.com/2w7e1jm.pnghttp://dragcave.net/image/eFGFz.gifhttp://dragcave.net/image/9hE5q.gif

Offline

 

#7 2012-02-29 14:26:41

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Bugged PHP

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

 

#8 2012-02-29 18:00:49

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Bugged PHP

Um, okay, I've switched it to:

Code:

<!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

 

#9 2012-02-29 18:41:56

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Bugged PHP

You said it was an HTML document...change the extension to PHP.  tongue


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#10 2012-03-01 04:38:24

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Bugged PHP

You have </body</html> (not </body></html>) at the end.  hmm  Also, did you put it on a server yet?

Offline

 

#11 2012-03-01 10:29:20

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Bugged PHP

scimonster wrote:

You have </body</html> (not </body></html>) at the end.  hmm  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

 

#12 2012-03-01 13:27:47

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Bugged PHP

Well, PHP will not work if it's not run on a server.

Offline

 

#13 2012-03-01 13:32:03

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Bugged PHP

For a server you could just do this.


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

Board footer