Hi!
So i am trying to compare a string which i got from a text file, with a string from a form. The problem is that the comparison won’t return true. ever! I have also tried if(strcmp($streng,$hotellnavn)==0){return true}, but that doesn’t work either. Can anybody help plz???
<?php
function finnesHotellnavniHotell($hotellnavn){
$text=file("HOTELL.txt");
echo "$hotellnavn";
foreach($text as $streng ){
echo $streng. "<br/>";
if($streng==$hotellnavn){ //why wont this compare??
echo "is even";
return true;
}
}
}
if(isset($_REQUEST['hotellnavn'])){
$hotellnavn=$_REQUEST['hotellnavn'];
if(finnesHotellnavniHotell($hotellnavn)){
echo "navnet finnes fra før av";
die;
}
$tekststreng=$_REQUEST['hotellnavn']."\n";
$myfile=fopen("HOTELL.txt", "a+");
fwrite($myfile, $tekststreng);
fclose($myfile);
}else{
echo "<h1>Her kan du registrere hotell</h1><br/>";
echo "<form action='' method='post' onsubmit='return valider()'>";
echo "Hotell navn<input type='text' name='hotellnavn' id='hotellnavn' onFocus='fokus(this)' onBlur='mistetFokus(this)' onMouseOver='musInn(this)' onMouseOut='musUt()'><br>";
echo "<input type='submit' name='knapp'>";
echo "</form>";
echo "<div id='melding'/>";
}
?>