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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validating on a string. 1

Status
Not open for further replies.

Nightsoft

Programmer
Aug 23, 2001
50
DK
I have this little piece of code that says that if [tt]$KONVERTERNAVN[/tt] = the string which contains : KFUM-Spejderne i Danmark
But even if the [tt]$KONVERTERNAVN[/tt] is something else than KFUM-Spejderne i Danmark it still runs through this code.
The [tt]$KONVERTERNAVN[/tt] is brought by an SQL query and if i just echo the [tt]$KONVERTERNAVN[/tt] then it print's out KFUM-Spejderne i Danmark
So how can it be that even if the [tt]$KONVERTERNAVN[/tt] is something else it does it anyway ?? Any good answers?

My code :
[tt]
Code:
/* some SQL code before this. */

if($KONVERTERNAVN = "KFUM-Spejderne i Danmark")
{
  $mail = "korpskontor@kfumscout.dk";
  echo '<script language=&quot;javascript&quot;>winopen(\'mailform.php?modtmail='.$mail.'\')</script>';
}
[/tt]

thnx Machine code Rocks:)
 
you are using the assignment operator in the line
if($KONVERTERNAVN = &quot;KFUM-Spejderne i Danmark&quot;)


You will want to change that to:
if($KONVERTERNAVN == &quot;KFUM-Spejderne i Danmark&quot;)
to change it to a comparison operation.
 
a single = is an assignment operator. It means &quot;left operand gets set to the value of the expression on the rights&quot;

more on assignment operators:

double == is a comparison operator. It is asking the question: Is the left operand equal to the right operand?

more on comparison operators:

Hope this helps :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top