Jump to content

simple variable question


Pyro4816

Recommended Posts

ok, well i need some help with if else and variables. I want to change a variable if a condition is met, but so far it has'nt worked, can anyone help me, here is an example: [code]<?php
$loginm = "1";
if($loginm = "1"){
$loginm = "2";
echo 'loginm changed to 2<br />';
echo $loginm;
echo '<br />';
}
if ($loginm="1"){
echo 'maby not<br />';
echo $loginm;
echo '<br />';
}else{
echo 'else';
}
?>
[/code]
what i want it to do is change the variable from that point on instead of it reverting in another section.
Link to comment
https://forums.phpfreaks.com/topic/28799-simple-variable-question/
Share on other sites

In your conditionals (if statemetns you need to use double equal signs to test for equality. When you use a single equal sign it is assigning the value.

This
[code]if($loginm = "1"){[/code]

means attempt to assign the value 1 to the variable $loginm. If it can then the condition passes, if it cannot then the condition fails.

You need to use this
[code]if($loginm == "1"){[/code]


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.