I have this login code, which works last night before I slept. Nobody used my computer. But this morning suddenly stopped working. My other codes also not working properly. Well in fact I made sure that they’re all working before I left them.
I reformatted my hard drive. I had a backup of the working project. I can’t really understand why it wouldn’t work. Anyone experienced this before?
<?php
include('conn.php');
$uname = mysql_real_escape_string($_POST['yname']);
$pword = $_POST['pword'];
$pwordmd5=md5($pword);
$result = query_database("SELECT * FROM admin_table WHERE Uneym = '$uname' AND Pwerd = '$pwordmd5'", "onstor", $link);
$num_rows = mysql_num_rows($result);
if ($result) {
if ($num_rows > 0) {
session_start();
$_SESSION['loginAdmin'] = "1";
//added feb 5 2011
$_SESSION['Uneym'] = $uname;
query_database("UPDATE admin_table SET Current='1' WHERE Uneym = '$uname' AND Pwerd = '$pwordmd5'", "onstor", $link);
header ("Location: adminpage.php");
}
else {
session_start();
$_SESSION['loginAdmin'] = "";
header ("Location: ../login.php");
}
}
else {
$errorMessage = "Error logging on, please try again.";
}
?>
I had this on php error log:
[12-Feb-2011 23:49:14] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in X:\wamp\www\pos\php\conn.php on line 6
[12-Feb-2011 23:49:14] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
in X:\wamp\www\pos\php\conn.php on line 6
[12-Feb-2011 23:49:14] PHP Fatal error: Maximum execution time of 60 seconds exceeded in X:\wamp\www\pos\php\conn.php on line 6
[12-Feb-2011 23:49:35] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in X:\wamp\www\pos\php\conn.php on line 6
[12-Feb-2011 23:49:35] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
in X:\wamp\www\pos\php\conn.php on line 6
[12-Feb-2011 23:49:35] PHP Fatal error: Maximum execution time of 60 seconds exceeded in X:\wamp\www\pos\php\conn.php on line 6
[12-Feb-2011 23:50:01] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in X:\wamp\www\pos\php\conn.php on line 6
[12-Feb-2011 23:50:01] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
in X:\wamp\www\pos\php\conn.php on line 6
Here’s conn.php which is being pointed out by the error logs:
<?php
function open_connection($host, $user, $password){
return mysql_connect($host, $user, $password);
}
function close_connection($link){
return mysql_close($link);
}
function query_database($query, $database, $link){
mysql_select_db($database, $link);
return mysql_query($query, $link);
}
function fetcher($result){
return mysql_fetch_assoc($result);
}
function query_checker($query){
if(!$query){
echo "error!".mysql_error();
}
return mysql_error();
}
$link=open_connection('localhost','root', '1234');
?>
Also haven’t modified conn.php, since its the first script that should be written when you want to connect to the database. And one more thing, before I reformatted, the whole project was one c drive. Now I’m on x drive. I’m not really sure if that’s the problem.
Your database appears to be down. Try restarting your mysql service.