I just started learning a little about PHP and sessions (using XAMPP to run PHP scripts).
I was watching a few vidoes and reading a few books before I started.
The thing I have here is from a video that I saw about PHP and sessions to get me going. I have a little problem here that the person in the video did not have.
This is my login.php code:
<?php
session_start(); // Starting Session
$error = ''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Brukernavn eller passord er ugyldig!";
} else {
// Define $username and $password
$username = $_POST['username'];
$password = $_POST['password'];
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost", "root", "");
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// Selecting Database
$db = mysql_select_db("logintest", $connection);
// SQL query to fetch information of registerd users and finds user match.
$query = mysql_query("select * from users where password='$password' AND username='$username'", $connection);
$rows = mysql_num_rows($query);
if ($rows == 1) {
$_SESSION['login_user']=$username; // Initializing Session
header("location: profile.php"); // Redirecting To Other Page
} else {
$error = "Brukernavn eller passord er ugyldig!";
}
mysql_close($connection); // Closing Connection
}
}
?>
When i now try to log in and with the right username i get this error:
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in
C:\xampp\htdocs\gauldaldesign\login.php:14 Stack trace: #0
C:\xampp\htdocs\gauldaldesign\index.php(2): include() #1 {main} thrown in
C:\xampp\htdocs\gauldaldesign\login.php on line 14
Anyone that can explain what this means and maybe what the problem can be? Maybe not the answer, but at least point me in the right direction so that I can learn from my mistakes.