Variable not working though out php mysql script

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
bigmuddyfoot
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Nov 16, 2017 7:42 pm

Thu Nov 16, 2017 7:46 pm

For some reason all my $var stop working after echo 'welcome '; echo $nip = $row['s']; and i dont understand why? :-x :-x

Code: Select all



<?php
session_start();

ini_set('display_errors',1); error_reporting(E_ALL);

?>


<!doctype html>
<html>
<head>
<meta charset="utf-8">

</head>

<body>
<div class="body">
  <div class="header"></div>
  <div class="nav">
<?php include("inc/nav.php"); ?>
  </div>
 
  <div class="content">
  <div style="width:200px; margin-left:auto; margin-right:auto;">
    <p>&nbsp;</p>
<?php 


$ipaddress = '';
    if (isset($_SERVER['HTTP_CLIENT_IP']))
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_X_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if(isset($_SERVER['REMOTE_ADDR']))
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else {
        $ipaddress = 'UNKNOWN';

	}
	
 
 
 
 
$servername = "*****";
$username = "*********";
$password = "***********";
$dbname = "**************";



// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
$connb = new mysqli($servername, $username, $password, $dbname, true);


// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 


$un = $_POST['username'];
$pw = $_POST['password'];
$store = $_POST['store'];   
$pw = md5($pw);
$ipaddress = $ipaddress;

$sql = "SELECT * FROM acclst  WHERE s = '$ipaddress' LIMIT 1 ";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
   // There is an ipaddress and it is approved
    while($row = $result->fetch_assoc()) {

        echo 'welcome ';
        echo $nip = $row['s'];   
		
		         // nothing beyond here works. 
		
echo $store;
$sqlb = "SELECT * FROM emp_list  WHERE `username` = '$un'  AND password = '$pw'  LIMIT 1 ";
$resultb = $connb->query($sqlb);

if ($result->num_rows > 0) {
   // There is an ipaddress and it is approved
    while($rowb = $result->fetch_assoc()) {

        echo $pw;
        echo 'welcome ';
        echo $rowb['namel'];        


    }
} 








    }
} 


else {
    // There is no ip address and you do not have access.
    echo "0 results";
}



?>




  </div>
  </div>

</div>
<div class="footer"></div>
</body>
</html>



User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 529
Joined: Mon Feb 22, 2016 5:52 pm

Fri Nov 17, 2017 8:44 am

This is really bad:

Code: Select all

$pw = md5($pw);
Do not use it any more, MD5 has been cracked and is not secure, look at the manual here for more information.


What errors are you getting?
Did your $vars work at one time and now they don't since a change was made?

Post Reply