|
|
|
(PHP) Ошибка Notice: Undefined variable...line2
|
|||
|---|---|---|---|
|
#18+
Если вопрос покажется глупым то я в PHP новичок. Есть два файла calc.htm и calc.php calc.htm: Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. calc.php: <? if($calc=="add"){ ; $res=$n1+$n2; } if($calc=="sub"){ ; $res=$n1-$n2; } if($calc=="mul"){ ; $res=$n1*$n2; } if($calc=="div"){ ; $res=$n1/$n2; } ?> <html> <head> <title>Калькулятор</title> </head> <body> <p>Ответ: <? echo "$res"; ?></p> </body> </html> Не понимаю где ошибка. При любых операциях (+, -, /, *) выходит ошибка: Notice: Undefined variable: calc in C:\Inetpub\wwwroot\php\calc.php on line 2 Notice: Undefined variable: calc in C:\Inetpub\wwwroot\php\calc.php on line 5 Notice: Undefined variable: calc in C:\Inetpub\wwwroot\php\calc.php on line 8 Notice: Undefined variable: calc in C:\Inetpub\wwwroot\php\calc.php on line 11 Îòâåò: Notice: Undefined variable: res in C:\Inetpub\wwwroot\php\calc.php on line 21 ???? Спасибо. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 01.08.2005, 16:49 |
|
||
|
(PHP) Ошибка Notice: Undefined variable...line2
|
|||
|---|---|---|---|
|
#18+
Не передаются переменные! Проблема register_globals ---------------------------------------- Артисты не приехали, приехали цыгане ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 01.08.2005, 17:21 |
|
||
|
(PHP) Ошибка Notice: Undefined variable...line2
|
|||
|---|---|---|---|
|
#18+
<p>Ответ: <? echo "$res"; ?></p> кавычки <p>Ответ: <? echo $res; ?></p> ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 01.08.2005, 23:45 |
|
||
|
(PHP) Ошибка Notice: Undefined variable...line2
|
|||
|---|---|---|---|
|
#18+
2 QueryMan И причем здесь кавычки? ---------------------------------------- Артисты не приехали, приехали цыгане ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 02.08.2005, 00:00 |
|
||
|
(PHP) Ошибка Notice: Undefined variable...line2
|
|||
|---|---|---|---|
|
#18+
4m@t!c Не передаются переменные! Проблема register_globals хмм значит надо на calc.php написать так: Код: plaintext 1. Выходит ошибка: Notice: import_request_variables() [function.import-request-variables]: No prefix specified - possible security hazard in C:\Inetpub\wwwroot\php\calc.php on line 2 Notice: Undefined variable: calc in C:\Inetpub\wwwroot\php\calc.php on line 3 Warning: extract() [function.extract]: First argument should be an array in C:\Inetpub\wwwroot\php\calc.php on line 3 Notice: Undefined variable: calc in C:\Inetpub\wwwroot\php\calc.php on line 4 4m@t!c пожалуйста подскажите как написать правильно как мне получить доступ к переменной calc ? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 02.08.2005, 07:54 |
|
||
|
(PHP) Ошибка Notice: Undefined variable...line2
|
|||
|---|---|---|---|
|
#18+
Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 02.08.2005, 08:27 |
|
||
|
(PHP) Ошибка Notice: Undefined variable...line2
|
|||
|---|---|---|---|
|
#18+
>4m@t!c пожалуйста подскажите как написать правильно как мне получить доступ к переменной calc ? Не смотря на то, что вы получили готовое решение - рекомендую читать ту статью до просветления. Что бы знать, что есть суперглобальные массивы, как они называются, для чего они нужны и как с ними работать. ИМХО, готовый код - медвежья услуга. ---------------------------------------- Артисты не приехали, приехали цыгане ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 02.08.2005, 10:12 |
|
||
|
(PHP) Ошибка Notice: Undefined variable...line2
|
|||
|---|---|---|---|
|
#18+
4m@t!c 2 QueryMan И причем здесь кавычки? --------------------------------------- Артисты не приехали, приехали цыгане Notice: Undefined variable: res in C:\Inetpub\wwwroot\php\calc.php on line 21 <p>Ответ: <? echo "$res"; ?></p> will produce $res кавычки <p>Ответ: <? echo $res; ?></p> will produce value of $res calc is array and when form is submitted it has 4 members you need to figure out what is the value of the checked item otherwise condition <? if($calc=="add"){ ; $res=$n1+$n2; } if($calc=="sub"){ ; $res=$n1-$n2; } if($calc=="mul"){ ; $res=$n1*$n2; } if($calc=="div"){ ; $res=$n1/$n2; never happens and $calc is not defined. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.08.2005, 23:24 |
|
||
|
(PHP) Ошибка Notice: Undefined variable...line2
|
|||
|---|---|---|---|
|
#18+
Код: plaintext 1. 2. 3. Just read and understand this and this . You should know, that variables produce value in double quote. ---------------------------------------- Артисты не приехали, приехали цыгане ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.08.2005, 13:49 |
|
||
|
|

start [/forum/topic.php?fid=23&msg=33195343&tid=1477804]: |
0ms |
get settings: |
7ms |
get forum list: |
10ms |
check forum access: |
2ms |
check topic access: |
2ms |
track hit: |
173ms |
get topic data: |
9ms |
get forum data: |
2ms |
get page messages: |
56ms |
get tp. blocked users: |
2ms |
| others: | 230ms |
| total: | 493ms |

| 0 / 0 |
