My problem is this, I am trying to create a simple session that allows me to log in using a Username and Password.
This is the session-
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
{
$connect = mysql_connect("localhost","root","root") or die ('Couldnt Connect!!');
mysql_select_db("AppDatabase") or die ('Couldnt find DB');
}
else
die ('You have not entered username or password');
?>
It is a simple session, I understand that this will return nothing just an empty screen. The problem is that I am unable to connect to the database I receive this error,
Warning: mysql_connect(): No such file or directory in /Users/JJoSmith/Sites/login.php
I have had this problem before where this has happened this is due to the port that the database is on. I am currently using MAMP to host my database. I have been using this as my database file to connect to the database.
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "root";
$conString = "mysql:host=$servername;port=8889;dbname=AppDatabase";
try {
$conn = new PDO($conString, $username, $password); // set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
};
?>
This allows the connection to the database and is working fine, for the session though Im just testing how it works and trying to implement it slowly before using my connection file. This is to see what isn't working and to test the session to make sure that it works correctly. As shown it is working, I hope someone can help me with my problem.