Post new topic    
Metal Slime
Send private message
help me with php 
 PostFri May 24, 2013 9:38 am
Send private message Reply with quote
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:
Quote:
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. Confused

I hope someone who knows about php can help me. Thanks. Smile
Liquid Metal King Slime
Send private message
 
 PostFri May 24, 2013 3:06 pm
Send private message Reply with quote
Code:

        if (!isset ($pancakecount)) /*||  ($pancakecount<3)*/
                {
                echo("<form>".PHP_EOL);
                echo ("<input>".PHP_EOL);
                echo ("<input>".PHP_EOL);
                echo("<button>eat a pancake</button>".PHP_EOL);
                echo("</form>").PHP_EOL;
                }


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:

                echo ("<input>".PHP_EOL);


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.
Metal Slime
Send private message
 
 PostFri May 24, 2013 5:21 pm
Send private message Reply with quote
Thanks for the reply and explainations. Smile

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.
Liquid Metal King Slime
Send private message
 
 PostFri May 24, 2013 7:16 pm
Send private message Reply with quote
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.
Metal Slime
Send private message
 
 PostSun Jun 02, 2013 9:27 am
Send private message Reply with quote
Thanks for you help. Smile
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:
Parse error: syntax error, unexpected ')', expecting ']' in ...\www\php-test\MarimonProjekt\statsrechner.php on line 19
Confused
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...
Liquid Metal King Slime
Send private message
 
 PostSun Jun 02, 2013 7:52 pm
Send private message Reply with quote
I think that your error message on line 19 is because you can't have a comment in the middle of a statement
Metal Slime
Send private message
 
 PostSun Jun 02, 2013 8:09 pm
Send private message Reply with quote
I removed the comment in line 19, but I still get the error message.

Quote:
Parse error: syntax error, unexpected ')' in ...\www\php-test\MarimonProjekt\statsrechner3.php on line 19


Do you have any other idea? xD
Metal King Slime
Send private message
 
 PostMon Jun 03, 2013 3:20 am
Send private message Reply with quote
I've completely forgotten what little I once knew about PHP, but could it be because you wrote _Post instead of _POST?
Metal Slime
Send private message
 
 PostMon Jun 03, 2013 4:49 am
Send private message Reply with quote
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. Grin

Code:
if ( isset($_POST["Lp"])  ) /**&& is_numeric($_POST['Lp']) && is_numeric($_POST['Mp']) && is_numeric($_POST['Ap'])**/


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? Confused
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.
Liquid Metal King Slime
Send private message
 
 PostMon Jun 03, 2013 2:59 pm
Send private message Reply with quote
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:

if(condition){
    //stuff
}elseif(condition){
    //other stuff
}else{
    //different stuff
}


Of course, you might as well stick with whatever style is recommended by the book/tutorial you are working with.
Metal Slime
Send private message
 
 PostMon Jun 03, 2013 6:59 pm
Send private message Reply with quote
Hey, thanks for you help. Smile
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! Grin

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! Grin
Display posts from previous: