aog Posted December 18, 2010 Share Posted December 18, 2010 Hello all. I am working and googling my keyboard out the window here with a script. I'm not really skilled in PHP or mySQL, but I try. My problem here is in the script you see below. If I enter the page from computer with IP:127.0.0.1 (witch is the lockalhost), the script works as I want. But if I enter the page from computer with ip 192.168.x.x (a computer on the LAN), the script does not work. I do get the echo ("You are $remote");, but the rest of the script wont work regardless of the 192.168.x.x can be found in $result = mysql_query("SELECT * FROM $table2 WHERE client_ip='$remote'"); or not. What am I doing wrong? EDIT: Fixed the = to == <?php include ("login.php"); include ("db_info.php"); $remote = $_SERVER['REMOTE_ADDR']; echo ("You are $remote"); mysql_select_db($db, $con); $result = mysql_query("SELECT * FROM $table2 WHERE client_ip='$remote'"); while($row = mysql_fetch_array($result)) { if ($row['client_ip'] == $remote) { $ip = $row['client_ip']; $name = $row['client_name']; echo $ip . " " . $name; echo "<br/>"; } else { echo "NOT VALID!"; } } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/222031-if-rowclient_ip-remote-issue/ Share on other sites More sharing options...
trq Posted December 18, 2010 Share Posted December 18, 2010 == is the comparison operator not = Quote Link to comment https://forums.phpfreaks.com/topic/222031-if-rowclient_ip-remote-issue/#findComment-1148867 Share on other sites More sharing options...
aog Posted December 18, 2010 Author Share Posted December 18, 2010 Yes, you are right. How ever, it didn't change my problem. Quote Link to comment https://forums.phpfreaks.com/topic/222031-if-rowclient_ip-remote-issue/#findComment-1148869 Share on other sites More sharing options...
quelle Posted December 18, 2010 Share Posted December 18, 2010 Your line echo ("You are $remote"); would go like this echo "You are " . $remote; Quote Link to comment https://forums.phpfreaks.com/topic/222031-if-rowclient_ip-remote-issue/#findComment-1148871 Share on other sites More sharing options...
aog Posted December 18, 2010 Author Share Posted December 18, 2010 Works both ways, but I guess you know what you're talking about. Fixed it, but it won't fix my main problem. Quote Link to comment https://forums.phpfreaks.com/topic/222031-if-rowclient_ip-remote-issue/#findComment-1148873 Share on other sites More sharing options...
aog Posted December 18, 2010 Author Share Posted December 18, 2010 Ok. I found one problem. Some how the last number of the ip 192.168.x.x was missing in the DB. (Sorry..) Once I fixed that, I discovered that else { echo "NOT VALID!"; } does not work either on local or remote computer. So, if IP is in table2, it works as intended, but not if the IP is missing in the table. What am I missing here? Quote Link to comment https://forums.phpfreaks.com/topic/222031-if-rowclient_ip-remote-issue/#findComment-1148878 Share on other sites More sharing options...
BlueSkyIS Posted December 18, 2010 Share Posted December 18, 2010 $sql = "SELECT * FROM $table2 WHERE client_ip='$remote'"; echo "sql: $sql <br />"; $result = mysql_query($sql) or die(mysql_error()); any change? is sql what you expect? Quote Link to comment https://forums.phpfreaks.com/topic/222031-if-rowclient_ip-remote-issue/#findComment-1148880 Share on other sites More sharing options...
BlueSkyIS Posted December 18, 2010 Share Posted December 18, 2010 if there should only be 1 result, don't use a while loop $row = mysql_fetch_array($result); and since the SQL asks for only those records where client_ip='$remote', there is no need for an if() to check whether it is in a record. Quote Link to comment https://forums.phpfreaks.com/topic/222031-if-rowclient_ip-remote-issue/#findComment-1148881 Share on other sites More sharing options...
BlueSkyIS Posted December 18, 2010 Share Posted December 18, 2010 so... $sql = "SELECT * FROM $table2 WHERE client_ip='$remote'"; $result = mysql_query($sql) or die(mysql_error()); if (mysql_numrows($result) > 0) { $row = mysql_fetch_array($result); $ip = $row['client_ip']; $name = $row['client_name']; echo $ip . " " . $name; echo "<br/>"; } else { echo "NOT VALID!"; } Quote Link to comment https://forums.phpfreaks.com/topic/222031-if-rowclient_ip-remote-issue/#findComment-1148882 Share on other sites More sharing options...
aog Posted December 18, 2010 Author Share Posted December 18, 2010 Sweet, that works. Thanks man. Quote Link to comment https://forums.phpfreaks.com/topic/222031-if-rowclient_ip-remote-issue/#findComment-1148884 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.