homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Problems with if statement

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

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

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

if ($ProductID=4) {

echo "Congratulation, records were found!";

} else {

echo "Sorry, no records were found!";


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

On this page, i have links to:




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]



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

think you need to change

if ($ProductID=4) {


if ($ProductID==4) {


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

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.


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

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:



echo $ProductID;



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


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

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

register_globals = On

in the php.ini file.


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

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.'

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved