Click to See Complete Forum and Search --> : database conection


franknu
07-20-2006, 10:20 AM
ok, i am having problems connecting to a database. i need help please

here is the code



<?

$host ="localhost";
$username ="silvapro_franknu";
$password ="abc123";!
$database ="silvapro_prueba";




// artist..

$artist_name = addslashes($artist_name);
$artist_release= addslashes($artist_release);
$artist_bio = addslashes($artist_bio);
$artist_news= addslashes($artist_news);
$artist_extra= addslashes($artist_extra);
$artist_picture= addslashes($artist_picture);



$db=mysql_connect ('$host', '$username', '$password') or die ('I cannot connect to the database because: ' . mysql_error());







if(!$db)

{
echo " Error: could not connect to database.";


}


//business owner
$sql="INSERT INTO `artist`(`artist_name`,`artist_release`,`artist_bio`,`artist_news`,`artist_extra`, `artist_picture`)
VALUES ('".$artist_name."','".$artist_release."','".$artist_news."','".$artist_extra."')";

$result = mysql_query($sql);
echo mysql_error();

if($result)
{
echo mysql_affected_rows()." .artist information Inserted. <br>";
}




?>



the display i am getting is

Error: could not connect to database.

can anyone help and tell me why is not working

LiLcRaZyFuZzY
07-20-2006, 10:25 AM
what is that exclamation point after the password variable declaration (top) ?

firman
07-20-2006, 10:27 AM
$dbh=mysql_connect ("localhost", " USER NAME ", " PASSWORD ") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db (" DBNAME ");



Try not using your variables at first to double check yourself.

franknu
07-20-2006, 10:32 AM
i made all the changes but nothing i keep getting the same mistakes


<?

$host ="localhost";
$username ="silvapro_franknu";
$password ="abc123";
$database ="silvapro_prueba";




// artist..

$artist_name = addslashes($artist_name);
$artist_release= addslashes($artist_release);
$artist_bio = addslashes($artist_bio);
$artist_news= addslashes($artist_news);
$artist_extra= addslashes($artist_extra);
$artist_picture= addslashes($artist_picture);



$dbh=mysql_connect ("localhost", "Silvapro_franknu ", "abc123") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("silvapro_prueba");








if(!$db)

{
echo " Error: could not connect to database.";


}


//business owner
$sql="INSERT INTO `artist`(`artist_name`,`artist_release`,`artist_bio`,`artist_news`,`artist_extra`, `artist_picture`)
VALUES ('".$artist_name."','".$artist_release."','".$artist_news."','".$artist_extra."')";

$result = mysql_query($sql);
echo mysql_error();

if($result)
{
echo mysql_affected_rows()." .artist information Inserted. <br>";
}




?>

aussie girl
07-20-2006, 10:40 AM
Is MySQL running?

firman
07-20-2006, 10:43 AM
you have $dbh in one part now


$db in another.

NogDog
07-20-2006, 10:46 AM
You're testing $db in your if statement, but you do not set it anywhere in the code. Did you mean to do...$db = mysql_select_db ("silvapro_prueba");...perhaps?