Access denied selecting database

Go to Ryanreese.us/blog.php

Fill out some random nonsense and then click submit. It gives me this error

dbselectAccess denied for user ‘ryanree1_reese’@‘localhost’ to database ‘blog’
[COLOR=#000000][FONT=Times New Roman]

Ignoring that “dbselect” for now, this is my code.

config.php
[/FONT][/COLOR]

<?php$host="localhost";
$username="ryanree1_reese";
$password="*************";
$tableName="userSubmitted";
$DbName="blog";

?>


checkInfo.php

<?phpsession_start();
include ("config.php");
?>
<!doctype html>
<html>
<head>
<title>check</title>
</head>
<body>
<?php


$contentOfPost=$_POST['contentOfPost'];
$submit=$_POST['submit'];
$date = date("Y/m/d");
$time = time();


$link = mysql_connect($host, $username, $password);


if(!$link){echo "link";die(mysql_error());}
$db_selected = mysql_select_db($DbName, $link);
if(!$db_selected){echo "dbselect";die(mysql_error());}
$insertionToDatabase="INSERT INTO $tableName ('PostNumber', 'Date', 'Time', 'Content') VALUES (NULL, '$date', '$time', '$contentOfPost')";


$result = mysql_query($insertionToDatabase);
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
echo $result;
mysql_close($link);


?>


</body>
</html>



[COLOR=#000000][FONT=Times New Roman]

Ignore any security for now. I have no need for it until I get this sorted out. I’ve deduced I can logon to the database, but my line in CheckInfo.php of mysql_select_db() is wrong. What’s the issue?

For reference, my DB name is ryanree1_blog and my table name is ryanree1_userSubmitted

Edit-Changed DB name to ryanree1_blog in the config.php file but no go. It’s back to just “blog” now.[/FONT][/COLOR]

This is not my area at all, but I notice you don’t have a gap between ?php and $host here:

<?php$host="localhost";

I’m pretty sure there should be a gap there.

It’s just from copy pasting.

Well, there’s meant to be a space after <?php, so give it a try! :slight_smile:

Did I not just say it’s from copy pasting?

The file has a line break…:slight_smile:

Yes, but it didn’t mean anything. :wink:

It does if you wonder why that was my response to your statement :).

No, to me it meant “I copied it from some reliable source in this form so I assume it’s OK and you are wrong.” That’s why it’s better to be specific and not assume your meaning is clear. :slight_smile:

It seems a bit odd that the spaces would be removed in a copy-paste anyhow. Are your sure the source code has a space in it? You also have this in your code: [COLOR="#FF0000"]<?php[/COLOR]session_start(); … again a case where a space is needed.

Of course, it may be that none of this is relevant to the issue, but it’s worth pointing out. :slight_smile:

I’m positive it’s not an issue. Can we just wait for those who can answer this? Granted this is keeping my thread at the top.

It’s also note worthy that the PHP wouldn’t have allowed it to go so far down the page as to my SQL statement, it surely would have died out from the get-go. I wrote that PHP myself, had I copied it, they would have been sure to make it not crappy and add in some security :).

Has a database named “blog” and user named “ryanree1_reese” been created with permissions to access blog? Normally you would do this by using the command line and running appropriate commands to create the db, user and grant blog permissions to the user. If so than I would recommend double checking the authentication credentials by connecting to MySQL and selecting the db directly via the command prompt. It sounds to me like either the connection is failing because of incorrect credentials or the user does not have permissions to access the database. The first step though is to determine whether a connection to MySQL can be established using the given credentials by eliminating PHP from the equation and using the command line. So verify that first than attempt to use the db to verify that once a connection has been established.

How would I do the appropriate commands?

Right now I have PHPmyadmin installed. I created the SQL database via some mysql thing, created a username I could use, and then went to PHP myadmin to create the table.

did you give access rights for your user? By default they have no rights…

Then that’s probably it. I went to my admin console yesterday because I thought of that but I didn’t see any option to give rights so I assumed I got it by default. How do I give mydelf access?

Depends a little bit on what version of PHPMA you’re using, but in general:
Go to the ‘server’ level of the breadcrumbs (Usually the “localhost” link at the top).
Click the “Privileges” tab.
Click on the Edit Privileges icon next to the user in question.
Scroll down to “Database-specific privileges”. Add the database in question.
Click the Edit Privileges button next to the database.
Select the relevant privileges (for a regular user access, SIUD should be sufficient.)
Click Go.

http://docs.cpanel.net/twiki/bin/view/AllDocumentation/CpanelDocs/MySQLDatabases#Modify%20a%20User's%20Privileges

Just posted and noted that others have answered with the same permission possible answers.

Deleting post

There is no priviledges option :(. I can screenshot my PHPmyadmin for those who want it.

Thing is, under account maintenance in mysql, there is no priviledges option.

Literally foudn it after I posted. It wasn’t there but I found it.

Now I have this error, which corrolates to this PHP line.

Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘PostNumber’, ‘Date’, ‘Time’, ‘Content’) VALUES (NULL, ‘2012/02/27’, ‘1330372760’ at line 1

$insertionToDatabase=“INSERT INTO $tableName (‘PostNumber’, ‘Date’, ‘Time’, ‘Content’) VALUES (NULL, ‘$date’, ‘$time’, ‘$contentOfPost’)”;

$result = mysql_query($insertionToDatabase);
if (!$result) {
die('Invalid query: ’ . mysql_error());
}

K, now a new error.

<?phpinclude ("config.php");
?>
<!doctype html>
<html>
<head>
<title>check</title>
</head>
<body>
<?php


$contentOfPost=$_POST['contentOfPost'];
$submit=$_POST['submit'];
$date = date("Y/m/d");
$time = time();


$link = mysql_connect($host, $username, $password);


if(!$link){echo "link";die(mysql_error());}
$db_selected = mysql_select_db($DbName, $link);
if(!$db_selected){echo "dbselect";die(mysql_error());}
$insertionToDatabase="INSERT INTO $tableName (PostNumber, Date, Time, Content) VALUES (NULL, $date, $time, $contentOfPost)";


$result = mysql_query($insertionToDatabase);
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
echo $result;
mysql_close($link);


?>


</body>
</html>

My error message is “[COLOR=#000000][FONT=Times New Roman]Invalid query: Unknown column ‘messageofblog’ in ‘field list’”

My table has 4 columns. PostNumber, Date, Time, and Content…“messageofblog” was what I inputted in my textarea, so tahts the “Content”[/FONT][/COLOR]

Everything is working now. Well, I may make a new thread if I can’t figure out why my date and time are showing up as just a whole load of 0’s, but anywa thanks to everyone :). Sorry for so many duplicate posts, I just wanted to give updates as I made a breakthrough so that people don’t work on old data.