Welcome to WebmasterWorld Guest from 54.163.40.152

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Problems with if statement

     

artie2004

2:37 pm on Oct 13, 2004 (gmt 0)

10+ Year Member



Hi. Could somebody please help? My problem has to do with the following code example.

<!- The name of this page is buynow.php4 -->

<html>
<body>
<?php
if ($ProductID=4) {

echo "Congratulation, records were found!";

} else {

echo "Sorry, no records were found!";

}
?>
</body>
</html>

<!- The name of this page is order_form.html -->

On this page, i have links to:

[example.com...]

[example.com...]

[example...]

My problem is when i click on each of the links above, they all display the same thing "Congratulation, records were found!"

Could someone tell me if there is anything wrong with this code? I am new to PHP, so i am not sure if i am just not using the correct syntax or something. Thank you.

[edited by: jatar_k at 5:10 pm (utc) on Oct. 13, 2004]
[edit reason] generalized urls [/edit]

benihana

2:41 pm on Oct 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



think you need to change

if ($ProductID=4) {

to

if ($ProductID==4) {

Knowles

4:30 pm on Oct 13, 2004 (gmt 0)

10+ Year Member



benihana is right about that, one = sets $ProductID to 4 and the two = checks the value of $ProductID to see if it equals 4. You may also run into problems if Register Globals is turned off (as it should be). We will wait and see on that before going into it.

artie2004

12:04 am on Oct 14, 2004 (gmt 0)

10+ Year Member



Thanks benihana, Knowles. I tried it already using "==" but it didn't work either. I have figured out why this was happening. I wanted to see if the value attached to the URL link(http://mysite.com/buynow.php4?ProductID=4) was being passed to buynow.php4 so i rewrote my code to the following:

<html>
<body>

<?php

echo $ProductID;

?>

</body>
</html>

As i suspected, the value wasn't getting passed to buynow.php4. My question is does anyone know why this is? Thank you.

artie2004

12:46 am on Oct 14, 2004 (gmt 0)

10+ Year Member



Never mind. I got it. I just had to set

register_globals = On

in the php.ini file.

mincklerstraat

9:23 am on Oct 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



People will probably have a more difficult time hacking your site if you turn this back off and use $_GET['ProductID'] instead of $ProductID; or just at the top of your script:
if(isset($_GET['ProductID'])) $ProductID = $_GET['ProductID'];
else $ProductID = '';
This is php coding 'best practices.'
 

Featured Threads

Hot Threads This Week

Hot Threads This Month