/    Sign up×
Community /Pin to ProfileBookmark

database conection

ok, i am having problems connecting to a database. i need help please

here is the code

[code=php]

<?

$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>”;
}

?>

[/code]

the display i am getting is

Error: could not connect to database.

can anyone help and tell me why is not working

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYJul 20.2006 — what is that exclamation point after the password variable declaration (top) ?
Copy linkTweet thisAlerts:
@firmanJul 20.2006 — $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.
Copy linkTweet thisAlerts:
@franknuauthorJul 20.2006 — i made all the changes but nothing i keep getting the same mistakes

[code=php]
<?

$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>";
}




?>
[/code]
Copy linkTweet thisAlerts:
@aussie_girlJul 20.2006 — Is MySQL running?
Copy linkTweet thisAlerts:
@firmanJul 20.2006 — you have $dbh in one part now


$db in another.
Copy linkTweet thisAlerts:
@NogDogJul 20.2006 — You're testing [b]$db[/b] in your if statement, but you do not set it anywhere in the code. Did you mean to do...[code=php]$db = mysql_select_db ("silvapro_prueba");[/code]...perhaps?
×

Success!

Help @franknu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...