I have created a login form and I am trying with php to connect on my database(localhost-PHPMyAdmin). I have created a database name "back".I created a table name it login and I have 4 things inside it,those things on the link(https://imgur.com/u9C1r1h ).
I give the part of codes, one for the php code that I have a problem with, and the second code of the form.
Furtheremore, "if(gethostname()==’the site I log in and that it is fine‘" there is a link here that I don’t want to give it ,but the site is right,similar with this " $mysqli = new mysqli($host, $user, $pass, $db,null,’here I have my socket and it is right ‘);" my socket is fine.Where is the problem can’t connect those two things?How to make those connected?
<?php
$host='localhost';
$db = 'back';
require_once "info.php";
$user=$DB_USER;
$pass=$DB_PASS;
if(gethostname()=='the site I log in and that it is fine') {
$mysqli = new mysqli($host, $user, $pass, $db,null,'here I have my socket and it is right ');
} else {
$mysqli = new mysqli($host, $user, $pass, $db); //here it shows me an error Failed to connect to MySQL: (1045) Access denied for user 'root'@'localhost' (using password: YES)
}
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" .
$mysqli->connect_errno . ") " . $mysqli->connect_error;
}
?>
<form method="post" action="index.php">
Username: <input name="username"/>
<br/>
Password: <input name="pass" type="password"/>
<br/>
<input type="submit" value="LOGIN"/>
<input name="p" type="hidden">
</form>
2
Answers
The issue you are encountering happens most probably was caused as you did not create a user with that username/password. If you have created the user, check your credentials. If not just put an empty string for the password. Normally, root users for localhost will not have a password assigned to it.
Get the post variables
Get the result from database
Please note that what I am showing above is not secure as I did not password_verify() it. But what I showed was merely going to give you an idea.