Page 1 of 1

SELECT command denied to user...

Posted: Thu Aug 24, 2006 7:53 pm
by cturner
Can someone please tell me why I am getting the following error:
SELECT command denied to user 'accountname'@'localhost' for table 'comments'. Thanks in advance.
Here is my code:

Code: Select all

require "config2.php"; 

if(!isset($_GET['page'])) { 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
} 

// Define the number of results per page 
$max_results = 1; 

// Figure out the limit for the query based 
// on the current page number. 
$from = (($page * $max_results) - $max_results); 

// Perform MySQL query on only the current page number's results 
$sql = mysql_query("SELECT * FROM items LIMIT $from, $max_results") or die ("Could not select the database because: " . mysql_error()); 

while($row = mysql_fetch_array($sql)){ 
    // Build your formatted results here. 
    echo $row['selectDay'].'-'.$row['selectMonth'].'-'.$row['selectYear'].'<br>'.$row['article_item'].'<br /> 
    <a href="modify_article.php?id='. $row['id'] .'">Modify</a> 
    <a href="delete_article.php?id='. $row['id'] .'">Delete</a>'; 
} 

// Figure out the total number of results in DB: 
$total_results = mysql_result(mysql_query("SELECT COUNT(*) AS Num FROM items"),0); 

// Figure out the total number of pages. Always round up using ceil() 
$total_pages = ceil($total_results / $max_results); 

// select the article with the matching comments 
$query = "SELECT article_item, COUNT(comments) AS numComm FROM users, items INNER JOIN users.comments ON items.article_item"; 

$result = mysql_query($query) or die (mysql_error()); 

if ($result < 0) { 
    echo "(0) comments"; 
} else { 
    echo $result; 
} 

// Build Page Number Hyperlinks 
echo "<center>"; 

if ($page == 1) { 
    echo "Previous "; 
} else { 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\">Previous</a> "; 
} 

for($i = 1; $i <= $total_pages; $i++){ 
    if(($page) == $i){ 
        echo "$i "; 
        } else { 
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; 
    } 
} 

if ($page == $total_pages) { 
    echo " Next"; 
} else { 
    echo " <a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\">Next</a>"; 
} 

echo "</center>"; 

// and close the database connection 
mysql_close();
My code was working before I placed the following code into it:

Code: Select all

$query = "SELECT article_item, COUNT(comments) AS numComm FROM users, items INNER JOIN users.comments ON items.article_item"; 

$result = mysql_query($query) or die (mysql_error()); 

if ($result < 0) { 
echo "(0) comments"; 
} else { 
echo $result; 
}

Posted: Thu Aug 24, 2006 7:56 pm
by blackbeard
It's not the PHP, it's the database. The user that you're using doesn't have the privledges to use the select command for that table.

Posted: Fri Aug 25, 2006 2:13 am
by volka