Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple if statement not working....why?

Status
Not open for further replies.

newphpbie

Programmer
Joined
Oct 17, 2003
Messages
110
Location
GB
HI, I am passing the variable $user in a hyperlink to the page Welcome.php

Welcome.php needs to collect $user and perform accordingly.

This is my code
Code:
<?php
session_start();

$user=$_REQUEST['user'];
echo '<html>';
echo '<head><title>The Welcome Page</title></head><framset cols=&quot;160,*&quot; framespacing=&quot;2&quot; frameborder=&quot;5&quot;>';

if($user=1){
echo '<frame src=&quot;main2.php&quot; name=&quot;main&quot; noresize>';

} else {
echo '<frame src=&quot;main.php&quot; name=&quot;main&quot; noresize>';
}

echo '<frame src=&quot;logo.php&quot; scrolling=&quot;auto&quot; noresize>';
echo '</frameset></html>';

?>
The only problem is that it will only show the main2.php page, even if the $user var is set to 2. Could someone tell me where I'm going wrong please. I know for certain the the var is being passed correctly and what it is set to each time, I just can't get my if statement to perform properly.

I'm sure this is something really small and silly, but I've been looking at it most of the day and I'm really lost.

Any help/advice would be honourable.

Thank you.

Tony
 
Try changing:

$user=$_REQUEST['user'];
to:

$user=&quot;$_REQUEST['user']&quot;;
 
Doesn't make a difference. I know that the var is correct...just the if statement which doesn't work.

If I put in a
Code:
print $user;

statement I get the correct var displayed to the screen...

I'm thinking it's got to be something to do with the
Code:
if($user=1)

statement.
 
Code:
if($user=1){
should be
Code:
if($user==1){
You are assigning
Code:
$user
a
Code:
1
, which will always evaluate to true.

//Daniel
 
Thank you danielhozac

I knew that from my java days but I just couldn't see it.....

A most honourable gentleman.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top