/    Sign up×
Community /Pin to ProfileBookmark

i am trying to insert into a database through a from i just cant see the problem. i am getting “No database selected” i dont even have that error cheking in 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());
mysql_select_db (“$database”);

if(!$db)

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

exit;
}

//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]

can anyone please help?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@Haafiz_DossaJul 17.2006 — make sure user silvapro_franknu is added to have permissions to use that database...it looks like a subuser of the main silvapro account so it might not have permissions by default

and replace mysql_select_db("$database"); with

mysql_select_db($database, $db) or die("Could not select: ".mysql_error($db));
Copy linkTweet thisAlerts:
@franknuauthorJul 17.2006 — ok, i gave permission to the user and made the changes however it doesnt seem to be connecting to the database because of something i cant see.

[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());
mysql_select_db($database, $db) or die("Could not select: ".mysql_error($db));







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




?>
<?php
echo "<br>";

print(htmlspecialchars(dirname(__FILE__))."<br>");


// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES.
if(!empty($_FILES["picture1"]))
{
$uploaddir = realpath("/home/silvapro/public_html");
var_dump($uploaddir);
var_dump($_FILES);
var_dump($_FILES["picture1"]["error"]);

if (move_uploaded_file($_FILES["picture1"]["tmp_name"], $uploaddir . $_FILES["picture1"]["name"])) {
echo("file uploaded");
} else {
echo ("error!");
}
}


?>

[/code]


this is the error i am getting

Error: could not connect to database.

please help
Copy linkTweet thisAlerts:
@aussie_girlJul 18.2006 — These variables should not be in double quotes..
[code=php]
$db=mysql_connect ("$host", "$username", "$password") or die ('I cannot connect to the database because: ' . mysql_error());
[/code]
Copy linkTweet thisAlerts:
@NogDogJul 18.2006 — These variables should not be in double quotes..
[code=php]
$db=mysql_connect ("$host", "$username", "$password") or die ('I cannot connect to the database because: ' . mysql_error());
[/code]
[/QUOTE]

They don't need to be in double-quotes, but it shouldn't hurt anything (other than a few more micro-seconds of processing time).
Copy linkTweet thisAlerts:
@NogDogJul 18.2006 — I can't see why you would get that error message, when you have the "or die()" clause after the mysql_connect() command. Does the remainder of the code after that get processed OK?
Copy linkTweet thisAlerts:
@aussie_girlJul 18.2006 — They don't need to be in double-quotes, but it shouldn't hurt anything (other than a few more micro-seconds of processing time).[/QUOTE]

hmmm.. it was my understanding that varaibles in double quotes were

treated as strings instead of the values,

So this line looks like it's trying to connect using the words

$host, $username, $password instead of the values they

are suppose to contain
Copy linkTweet thisAlerts:
@NogDogJul 18.2006 — If variable names are in a single-quoted string, then they are not "interpolated"; but when they are within a double-quoted or heredoc string literal, then they [i]are[/i] interpolated and the variable's value is used at that point in the string.
[code=php]
$test = "foobar";
echo '$test'; // outputs "$test"
echo "$test"; // outputs "foobar"
// also outputs "foobar":
echo <<<EOD
$test
EOD;
[/code]
×

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.6,
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,
)...