help me with php

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

help me with php

Post by marionline »

Hello,

I need some help with php scripts.
Some parts get not displayed here, so this is the Pastbin link: http://pastebin.com/Z9hTA6N6

The Error my webbrowser shows says:
Notice: Undefined variable: pancakecount in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\php-test\Walkthroug\kitchen.php on line 12
I know, that I have to define the variable pancakecount, if my browser is correct, but I don't understand why I get this message, I thought in line 12 the variable is defined. :???:

I hope someone who knows about php can help me. Thanks. :)
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Code: Select all

        if &#40;!isset &#40;$pancakecount&#41;&#41; /*||  &#40;$pancakecount<3&#41;*/
                &#123;
                echo&#40;"<form>".PHP_EOL&#41;;
                echo &#40;"<input>".PHP_EOL&#41;;
                echo &#40;"<input>".PHP_EOL&#41;;
                echo&#40;"<button>eat a pancake</button>".PHP_EOL&#41;;
                echo&#40;"</form>"&#41;.PHP_EOL;
                &#125;
EDIT: I see that the forum mangled those lines beyond recognition. :(

the condition of this "if" block means that the echo commands are only run when $pancakecount is not set. The ! symbol means not, so !isset() checks that a variable is not set yet.

Code: Select all

                echo &#40;"<input>".PHP_EOL&#41;;
This line adds 1 to the $pancakecount and then uses that value, but since $pancakecount has not been set yet, you cannot add to it.
Last edited by Bob the Hamster on Fri May 24, 2013 7:08 pm, edited 1 time in total.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Thanks for the reply and explainations. :)

I wanted to set the variable pancakecount in line 12, but even if I remove the ++ I still get the error message.
So, how can I set the variable (if it's not set)?
In another php page setting the value of the variable worked like this inside a from.
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Line 12 is not where you want to set the variable. Line 12 is creating an HTML form input field. That field will show up in the web browser, and you will be able to type a number into it. When yoiu submit the form, the variable will be in $_POST["pancakecount"]

Line 20 is the line that actually sets the $pancakecount variable.
Last edited by Bob the Hamster on Fri May 24, 2013 7:17 pm, edited 1 time in total.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Thanks for you help. :)
I didn't get the scipt to work like I wanted, so I gave up on it and started to work throug a book about php, telling me it will be the best to start in the beginning.

Now I'm stuck again, trying to make a calculator-page. :-/

Code: Select all

Parse error&#58; syntax error, unexpected '&#41;', expecting '&#93;' in ...\www\php-test\MarimonProjekt\statsrechner.php on line 19
:???:
I think i'm doing something wrong with the if-clauses beside, this error message, it seems like the code of the inner if-clause is not beeing executed at all. :/
While tring to fix that problem, the error message posted avove showed up.
Maybe the break inside the inner if-clause isb also not the best idea?
http://pastebin.com/7qg5Eqcz

Well, seems like I need help again...
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

I think that your error message on line 19 is because you can't have a comment in the middle of a statement
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

I removed the comment in line 19, but I still get the error message.
Parse error: syntax error, unexpected ')' in ...\www\php-test\MarimonProjekt\statsrechner3.php on line 19
Do you have any other idea? xD
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

I've completely forgotten what little I once knew about PHP, but could it be because you wrote _Post instead of _POST?
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Hey, ^^"
Thank for the idea.
I tried that, but it didn't change the error-message.
I'd say _post and _POST are treated the same, but I'll re-reread this in my book, to be sure.

... I just played with the brackets while writing this post and found the error-source. It was an missing () around the whole isstet-function. :D

Code: Select all

if &#40; isset&#40;$_POST&#91;"Lp"&#93;&#41;  &#41; /**&& is_numeric&#40;$_POST&#91;'Lp'&#93;&#41; && is_numeric&#40;$_POST&#91;'Mp'&#93;&#41; && is_numeric&#40;$_POST&#91;'Ap'&#93;&#41;**/
But, I'm getting an other error now:
Parse error: syntax error, unexpected T_ELSEIF in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\php-test\MarimonProjekt\statsrechner3.php on line 55
Why is the else-if not expected? :???:
I guess the problem is still with the two if-blocks, but I'm somehow blind for what causes the error.

http://pastebin.com/sRwpSBFt That's how the code lookes now.
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

It looks like you are missing the final } at the end of the "if" block right before the "elseif"

Here is how I like to write my conditional blocks:

Code: Select all

if&#40;condition&#41;&#123;
    //stuff
&#125;elseif&#40;condition&#41;&#123;
    //other stuff
&#125;else&#123;
    //different stuff
&#125;
Of course, you might as well stick with whatever style is recommended by the book/tutorial you are working with.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Hey, thanks for you help. :)
I'm very thankfull that you help me.

If I'd not asked for help, I'd have given up on this, but now it works!
I'm happy! :D

I'll try to get used to the style suggested. It feels better, (still I don't like how it lookes), but it's also used in the book, and as I know now, not without a reason. ^^"

Thanks a lot again for all the help! :D
Post Reply