Quote from your question:
if (!$con)
{
die('Could not connect: ');
}
else
{ echo "connection failed....";}
... you do notice it doesn't make much sense? it is saying if (something) { //could not connect } else { //connection failed } so your code thinks it is always failing.
What you should have is something like
$con = mysql_connect("localhost", "username" , "password");
if ($con === false)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ManagersDatabase", $con);
So it would actually print out anything.
Also, you should have either display_errors enabled to get the errors on screen or error_log in use so you would get the errors logged to somewhere.
In addition, please check you actually have the mysql extension enabled and in use, and mysql_connect() function available. phpinfo(); will tell what extensions you have, and function_exists() can tell you have the function available.
So, things to do:
- Fix your code logic like listed above
- Enable error printing or logging
- Check that you have the mysql extension enabled
- Check that mysql_connect() function actually is callable
Edit. as the missing mysql extension seems to be the problem ('call to undefined function mysql_connect'):
First of all, you need to have access to your PHP configuration. If this is your local installation or server, you should have that - if you are using someone elses hosting, they are the people who should change these things.
Given some assumptions, such as
- you are using your local apache server
- you are not using XAMPP or any other *AMP products, but vanilla installations
this is what you should do:
- Find your php.ini configuration file or create one based on example files in the PHP folder if you don't have one
- Find the lines below (.dll for windows, .so for linux, don't know about others)
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_pdo_mysql.dll
- Strip out the comment (the first ';') from the one you want to use. You are using the first one in your example, the others are for using other abstractions described in some of the other postings here, so if you want to go with the code you have, you'd uncomment the first one.
- Enable "display_startup_errors" also if you want to see any configuration problems immediately
- Check that "extension_dir" setting is correct, and is pointing to the folder where you have the above .dll extensions
- Restart your apache server