database : mysql
tool: phpmyadmin
today my supervisor set up the web on the companies server. when its all settled, we try out the site. the index.php(first page) loads then when we try to login page(index.php + login.php), we get :
Connection failed: SQLSTATE[HY000] [2002] Connection timed out
it probably has to do with connecting to the server. and i really have no clue whats going on. unless there is something wrong with these pages then its the server configuration?
login.php:
<?php
if(isset($_POST['login']))
{
require "connection.php";
$email = $_POST['email'];
$password = $_POST['pass'];
$query = $dbh->prepare("SELECT id,name,email,password FROM users WHERE email = :email");
$query->bindParam(':email', $email, PDO::PARAM_STR);
$userData = $query->fetch(PDO::FETCH_ASSOC);
$userEmail = $userData['email'];
$hash = $userData['password'];
if(!password_verify($password, $hash) && $email != $userEmail)
{
$error = "";
$error .= "Incorrect email and/or password";
}
else
{
session_start();
$_SESSION['sess_user_id'] = $userData['id'];
$_SESSION['sess_name'] = $userData['name'];
header('Location: home.php');
exit;
}
}
else
{
header ("location : index.php");
exit;
}
?>
connection.php:
<?php
$username = "username";
$password = "password";
$connection = "mysql:host=1.2.3.4;dbname=dbname";
try {
$dbh = new PDO($connection, $username, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>
this is the index.php page just incase:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8">
<title>EMS</title>
<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" src="js/jquery 1.8.2.js"></script>
</head>
<body>
<div id="page-wrap">
<h2>Event Management System<a href="#" id="login">Login</a><label>|</label><a href="#" id="sign">Sign Up</a></h2>
</div>
<div id="s-overlay" class="s-overlay"></div>
<div id="tsu-wrap">
<form name="register" class="register" method="post" action="index.php">
<table id="tsu">
<thead><tr><th>Sign Up</th></tr></thead>
<tbody>
<tr><td class="rd"><input type="text" name="fulln" placeholder="Norin Nong" required></td></tr>
<tr><td class="rd"><input type="email" name="em" placeholder="norin@gmail.com" required></td></tr>
<tr><td class="rd"><input type="text" name="tel" placeholder="012-9635874" required></td></tr>
<tr><td class="rd"><input type="password" name="pass" placeholder="Something Secure" required></td></tr>
<tr><td><label>Minimum 8;at least 1 number;at least 1 letter;special characters(optional):!@#$%</label></td></tr>
<tr><td class="r"><input type="password" name="cpass" placeholder="Confirm Password" required></td></tr>
<tr><td><input type="submit" name="signup" class="signup"> <input type="button" class="cancel" value="Cancel" /></td></tr>
</tbody>
</table>
</form>
</div>
<div id="l-overlay" class="l-overlay"></div>
<div id="tl-wrap">
<form name="login" method="post" action="index.php" id="login-form">
<table id="tl">
<thead><tr><th>Login</th></tr></thead>
<tbody>
<tr><td class="log"><input type="text" name="email" placeholder="EMAIL" autofocus ></td></tr>
<tr><td class="lg"><input type="password" name="pass" placeholder="PASSWORD"></td></tr>
<span class="errormsg"></span>
<tr><td><input type="submit" name="login" class="login">
<input type="submit" class="close" value="Cancel" /></td></tr>
</tbody>
</table>
</form>
</div>
<script type="text/javascript">
jQuery(function(){
$("#signup").click(function(){
$(".error").hide();
var hasError = false;
var passwordVal = $(".pass").val();
var checkVal = $(".cpass").val();
if (passwordVal != checkVal ) {
$(".cpass").after('<br><span class="error">Passwords do not match.</span>');
hasError = true;
}
if(hasError == true) {return false;}
});
});
</script>
</body>
</html>
TIA!