Rybat
1
I am newbie in php
I get this error message kindly help.
my connect.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "user_login";
try {
//creating connection to mysql
$dbh = new PDO("mysql: host=$localhost;dbname=user_login", $username, $password);
// set the PDO error mode to exception
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
exit;
}
?>
rpkamp
3
Could you post your connect.php
where the error is happening?
Rybat
5
My connect.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "user_login";
try {
//creating connection to mysql
$dbh = new PDO("mysql: host=$localhost;dbname=user_login", $username, $password);
// set the PDO error mode to exception
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
exit;
}
?>
rpkamp
6
There is no variable $localhost
defined in your script. There is however a variable $servername
.
1 Like
Rybat
7
Thanks bro…It worked changed the variable $servername to $localhost and it worked!! Much thanks!!!
rpkamp
8
If would have changed $localhost
to $servername
as that makes more sense, but yeah, the other way around works too 
1 Like
Rybat
9
Sure it does…Thanks for the help!
system
Closed
10
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.