Twango Posted April 11, 2011 Share Posted April 11, 2011 Pretty simple thing:here's my code; Enter website name in this format: www.site.tld (TLDs are .com, .net, .co etc):<br/><form method="post" action="index.php"><input type="text" name="ur"/><input type="submit" value="Check"/></form><?php$c = $_POST['ur'];$bado = fopen("bad.txt","r");$bad = $bado;fclose($bado);$goodo = fopen("good.txt","r");$good = $goodo;fclose($goodo);$neuo = fopen("neu.txt","r");$neu = $neuo;fclose($neuo);//Checksif ($c){if (substr_count($bad, $c) > 0){$stat = "Bad";}elseif (substr_count($good, $c) > 0){$stat = "Good";}elseif (substr_count($neu, $c) > 0){$stat = "Neutral";}else{$stat = "Not in our database";}if ($stat == "Bad"){echo "<h2><font color=red>The website $c has a bad record</font></h2>";}elseif ($stat == "Good"){echo "<h2><font color=lime>The website $c has a good record</font></h2>";}elseif ($stat == "Neutral"){echo "<h2><font color=yellow>The website $c has a neutral</font></h2>";}else{echo "<h2><font color=blue>The website $c has no records</font></h2>";}}?> So, why is it always giving the no record thing? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 11, 2011 Share Posted April 11, 2011 If it's printing the statement in the else, then none of the conditions in the if are true. Link to comment Share on other sites More sharing options...
Twango Posted April 11, 2011 Author Share Posted April 11, 2011 right but I'm saying, I put www.test.com in the bad category, then typed in www.test.com and it showed "no results" Link to comment Share on other sites More sharing options...
justsomeguy Posted April 11, 2011 Share Posted April 11, 2011 Right, and I'm saying that none of the if statements match. If you don't believe me, print out all of the variables you're using to check the values of everything. Start with $c. Link to comment Share on other sites More sharing options...
Twango Posted April 11, 2011 Author Share Posted April 11, 2011 It's saying "Resource id #6, Resource id #5, and Resource id #7"What does this mean? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 11, 2011 Share Posted April 11, 2011 Those are probably from fopen. Things like fopen and mysql_query return resource objects, and when you try to print them they just print "Resource" and a number. Link to comment Share on other sites More sharing options...
Twango Posted April 11, 2011 Author Share Posted April 11, 2011 Okay so how would i fix this? O_O Link to comment Share on other sites More sharing options...
justsomeguy Posted April 11, 2011 Share Posted April 11, 2011 When you're reading from a file, you can either use fopen, fread, and fclose, or you can use file_get_contents. You're missing fread, you just open the file and close it again without reading from it.http://www.php.net/manual/en/function.fread.phphttp://www.php.net/manual/en/function.file-get-contents.phpYou can also use the file function to read a file and store the lines in an array:http://www.php.net/manual/en/function.file.phpIf each URL is on its own line, you can use file to read the lines into an array, and then use in_array to check if the string you're looking for is in the array. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.