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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.