MySQL and PHP connection Fatal error

http://efedolaman-projekte.rf.gd

Hello,
Everytime I try to log in I get this error and I don’t know what to do.

Error:

Fatal error : Uncaught mysqli_sql_exception: No such file or directory in /home/vol10_1/infinityfree.com/if0_36187541/htdocs/db_conn.php:9 Stack trace: #0 /home/vol10_1/infinityfree.com/if0_36187541/htdocs/db_conn.php(9): mysqli_connect(‘localhost’, ‘root’, Object(SensitiveParameterValue), ‘test_db’) #1 /home/vol10_1/infinityfree.com/if0_36187541/htdocs/login.php(3): include(‘/home/vol10_1/i…’) #2 {main} thrown in /home/vol10_1/infinityfree.com/if0_36187541/htdocs/db_conn.php on line 9

Here is my code:

db_conn.php

<?php

$sname= "Username_if0...";
$unmae= "Server...mysql...";
$password = "xxxx";

$db_name = "db_name";

$conn = mysqli_connect($sname, $unmae, $password, $db_name);

if (!$conn) {
	echo "Fehler: Bitte wenden sie sich bei ihrem Administrator!";
}

login.php

<?php 
session_start(); 
include "db_conn.php";

if (isset($_POST['uname']) && isset($_POST['password'])) {

	function validate($data){
       $data = trim($data);
	   $data = stripslashes($data);
	   $data = htmlspecialchars($data);
	   return $data;
	}

	$uname = validate($_POST['uname']);
	$pass = validate($_POST['password']);

	if (empty($uname)) {
		header("Location: index.php?error=Benutzername wird benötigt");
	    exit();
	}else if(empty($pass)){
        header("Location: index.php?error=Passwort wird benötigt");
	    exit();
	}else{
		$sql = "SELECT * FROM users WHERE user_name='$uname' AND password='$pass'";

		$result = mysqli_query($conn, $sql);

		if (mysqli_num_rows($result) === 1) {
			$row = mysqli_fetch_assoc($result);
            if ($row['user_name'] === $uname && $row['password'] === $pass) {
            	$_SESSION['user_name'] = $row['user_name'];
            	$_SESSION['name'] = $row['name'];
            	$_SESSION['id'] = $row['id'];
            	header("Location: home.php");
		        exit();
            }else{
				header("Location: index.php?error=Benutzername oder Passwort ist falsch");
		        exit();
			}
		}else{
			header("Location: index.php?error=Benutzername oder Passwort ist falsch");
	        exit();
		}
	}
	
} else{
	header("Location: index.php");
	exit();
}

Thanks!

Please read

8 Likes

Is this correct? $sname suggests it would contain the hostname, and $uname the username. If you provide the options to mysqli_connect in the wrong order, then it won’t work.

6 Likes

Yeah, it worked!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.