SRL Archive - General

mysql database error....


Starbridge

2009-01-11 16:06:22

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]<?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_user,$mysql_password);
mysql_select_db($mysql_database,$mysql_host);
if (!$con)
{
die(mysql_error());
} else {
if (!mysql_select_db($Mysql_database,$mysql_user,$mysql_password))
{
echo "Worked!";
}
}
?>
[/PHP] and here is what I get…[PHP]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)[/PHP]
Please help as soon as possible :redface: :redface: :redface:

A G E N T

2009-01-12 18:52:14

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

2009-03-21 07:00:57

Try this:

[PHP]
<?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';
}
?>
[/PHP]

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?

2009-03-21 08:24:18


<?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_password);

// This might be interesting too (saves you that extra check):
// $con = mysql_connect($mysql_host,$mysql_user,$mysql_password) 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,$mysql_password))
{
echo "Worked!";
}*/
// do stuff here.


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

Grippy

2009-03-31 11:30:36

Perhaps almost totally off-topic, but if you are interested in writing text-based games, first be sure you are familiar with Inform 7.