PDA

View Full Version : mysql database error....



Starbridge
01-11-2009, 09:06 PM
Hey guys, I'm trying to make a text based game, and I need some help, I tried setting up a mysql database, and tried to connect to it with this code,
<?php

$mysql_host = "edited out";
$mysql_database = "edited out";
$mysql_user = "edited out";
$mysql_password = "edited out";

$con = mysql_connect($mysql_database,$mysql_host,$mysql_u ser,$mysql_password);
mysql_select_db($mysql_database,$mysql_host);
if (!$con)
{
die(mysql_error());
} else {
if (!mysql_select_db($Mysql_database,$mysql_user,$mys ql_password))
{
echo "Worked!";
}
}
?>
and here is what I get...
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'mysql3.000webhos'@'server15.000webhost.com' (using password: YES) in /home/a4605859/public_html/cfg.php on line 9

Free Web Hosting

PHP Error Message

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/a4605859/public_html/cfg.php on line 10

Free Web Hosting
Access denied for user 'mysql3.000webhos'@'server15.000webhost.com' (using password: YES)
Please help as soon as possible :redface: :redface: :redface:

A G E N T
01-12-2009, 11:52 PM
Quite simply, your username and/or password is wrong.
Reading quickly from your site (000webhosting.com), your user should be of the form: username_dbname, like: stephen_database1. You seem to have 'mysql3.000webhos' as your user (judging from the warning output).
-AGENT

Justcheat
03-21-2009, 11:00 AM
Try this:



<?php

$mysql_host = "localhost";
$mysql_database = "db";
$mysql_user = "user";
$mysql_password = "pass";

$con = mysql_connect($mysql_host ,$mysql_user, $mysql_password);
mysql_select_db($mysql_database);
if (!$con)
{
die(mysql_error());
}
else
{
echo 'Connected';
}
?>


Your db connection line was not okay, and you did the following:

You checked if the connection died with (!$con)
That was okay, but after the else you typed a if (there is a elseif function)
But that is not the biggest fault, you checked after the else again if the connection died, you had a '!' before it..

If you script php, first brainstorm if the script won't work;)

If it still doesn't work, contact me:D

Wizzup?
03-21-2009, 12:24 PM
<?php

$mysql_host = "edited out";
$mysql_database = "edited out";
$mysql_user = "edited out";
$mysql_password = "edited out";

//mysql_connect doesn't take mysql_database as argument. (Read the PHP Manual.)
$con = mysql_connect($mysql_host,$mysql_user,$mysql_passw ord);

// This might be interesting too (saves you that extra check):
// $con = mysql_connect($mysql_host,$mysql_user,$mysql_passw ord) or die(mysql_error());

//mysql_select_db($mysql_database,$mysql_host);
// No need to select it twice.
if (!$con)
{
die(mysql_error());
} else {
//mysql_select_db takes one argument, and one optional argument.
//you also used an uppercase M for the var. PHP's var's are case sensitive.
if(mysql_select_db($mysql_database) {
echo 'Worked';
}
/*if (!mysql_select_db($Mysql_database,$mysql_user,$mys ql_password))
{
echo "Worked!";
}*/
// do stuff here.


// don't forget to close your connection.
mysql_close($con);
}
?>

Grippy
03-31-2009, 03:30 PM
Perhaps almost totally off-topic, but if you are interested in writing text-based games, first be sure you are familiar with Inform 7 (http://www.inform-fiction.org/I7/Inform%207.html).