我不明白为什么第二个mysql外观不起作用。
从我所知道的$sqlb = "SELECT * FROM emp_list WHERE password = '$pw' AND username = '$un' LIMIT 1 ";
在第二行的位置,$ pw或$ un中没有值,实际上我无法回应任何
$un = $_POST['username'];
$pw = $_POST['password'];
$store = $_POST['store'];
$pw = md5($pw);
$ipaddress = $ipaddress;
从一开始或$ nip从第一个循环我做错了什么?
<?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 = "localhost";
$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'];
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// this does not echo
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()) {
// none of this echo's
echo $pw;
echo 'welcome ';
echo $rowb['namel'];
}
}
}
}
else
{
// There is no ip address and you do not have access.
echo "0 results";
}
?>
答案 0 :(得分:0)
这是我发现的。现在它工作正常。
// Create connection
$conn = new mysqli($servername, $username, $dbpassword, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$un = $_POST['username'];
$pw = $_POST['password'];
$store = $_POST['store'];
// $pw = password_hash('donavons', PASSWORD_DEFAULT);
$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 '<pre>IP Address Verified.' . $row['s'] . '</pre>';
$sqlb = "SELECT * FROM emp_list WHERE username = '$un' LIMIT 1 ";
$result = $conn->query($sqlb);
if ($result->num_rows > 0) {
// There is an ipaddress and it is approved
while($rowb = $result->fetch_assoc()) {
$hash = $rowb['password'];
if (password_verify($pw, $hash))
{
答案 1 :(得分:-2)
不确定我是否理解你的问题,但尝试这样的事情:
$sqlb = "SELECT * FROM emp_list WHERE password = " . $pw . " AND username = " . $un . " LIMIT 1 ";