Jump to content

"if ($row['client_ip'] = $remote) {"-issue


aog

Recommended Posts

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);

?>

Link to comment
https://forums.phpfreaks.com/topic/222031-if-rowclient_ip-remote-issue/
Share on other sites

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?  :shrug:

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!";
}

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.