问题
I have a strange error message after using the post to wall function. It did successfully post to the wall however i got a very weird strange error.
[Mon Dec 28 12:47:36 2015] [error] [client 5.29.224.120] PHP Notice: Use of undefined constant female - assumed 'female' in /datas/vhosts/nf.com/httpdocs/agence1948/result.php on line 178, referer: https://nf.com/agence1948/question.php [Mon Dec 28 12:47:36 2015] [error] [client 5.29.224.120] PHP Notice: Use of undefined constant male - assumed 'male' in /datas/vhosts/nf.com/httpdocs/agence1948/result.php on line 182, referer: https://nf.com/agence1948/question.php
I use this code
<?php if($_SESSION['score'] >= 15 && $_SESSION['score'] <= 20): ?>
<?php if($_SESSION['gender'] == female): ?>
<img src="img/Refaeli.jpeg"/>
<?php endif; ?>
<?php if($_SESSION['gender'] == male): ?>
<img src="img/avidan.jpg"/>
<?php endif; ?>
someone knows whats is the problem?
thank you
回答1:
male
and female
are strings, so enclose with quotations!
It should be:
<?php if($_SESSION['gender'] == 'female'): ?>
<img src="img/Refaeli.jpeg"/>
<?php endif; ?>
<?php if($_SESSION['gender'] == 'male'): ?>
<img src="img/avidan.jpg"/>
<?php endif; ?>
回答2:
male
and female
should be enclosed with quotes as they are strings. E.g
<?php if($_SESSION['gender'] == 'female'): ?> OR
<?php if($_SESSION['gender'] == 'male'): ?>
回答3:
Two error in your code
1) You need to end first if condition
2) male and female
inside quotes for comparision .Otherwise it is treated as constant
<?php if ($_SESSION['score'] >= 15 && $_SESSION['score'] <= 20): ?>
<?php if ($_SESSION['gender'] == "female"): ?>// use quotes
<img src="img/Refaeli.jpeg"/>
<?php endif; ?>
<?php if ($_SESSION['gender'] == "male"): ?>// use quotes
<img src="img/avidan.jpg"/>
<?php endif; ?>
<?php endif; ?>// end first condition
来源:https://stackoverflow.com/questions/34493167/php-notice-use-of-undefined-constant