Grow your CSS skills. Land your dream job.

PHP Error Warning

  • # April 8, 2010 at 2:39 pm

    Hi, I’m having some trouble with a script I’m making I see this error:

    Warning: mysql_query() [function.mysql-query]: Access denied for user ‘rettro’@’localhost’ (using password: NO) in /home/rettro/public_html/admin/post.php on line 52

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/rettro/public_html/admin/post.php on line 52

    I’ll show you the page If that helps?

    Code:
    < ?php require('config.php'); ?>
    < ?php include('header.php'); ?>
    < ?php

    if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    die("Invalid ID specified.");
    }

    $id = (int)$_GET['id'];
    $sql = "SELECT * FROM php_blog WHERE id='$id' LIMIT 1";

    $result = mysql_query($sql) or print ("Can't select entry from table php_blog.
    ” . $sql . “
    ” . mysql_error());

    while($row = mysql_fetch_array($result)) {

    $date = date(“l F d Y”, $row['timestamp']);

    $title = stripslashes($row['title']);
    $entry = stripslashes($row['entry']);
    $password = $row['password'];
    $get_categories = mysql_query(“SELECT * FROM php_blog_categories WHERE `category_id` = $row[category]“);
    $category = mysql_fetch_array($get_categories);

    if ($password == 1) {
    if (isset($_POST['username']) && $_POST['username'] == $my_username) {
    if (isset($_POST['pass']) && $_POST['pass'] == $my_password) {
    ?>

    “>< ?php echo $title; ?>

    < ?php echo $entry; ?>

    < ?php

    }
    else { ?>

    Sorry, wrong password.

    < ?php
    }
    }
    else {
    echo '

    ‘ . $title . ‘

    ‘;

    printf(“

    This is a password protected blog post. If you have a password for the post, enter it below.

    “);

    printf(“



    “,$id);
    print “

    “;
    }
    }
    else { ?>

    “>< ?php echo $title; ?>

    < ?php echo $entry; ?>

    < ?php
    }
    }
    $commenttimestamp = strtotime("now");
    $sql = "SELECT * FROM php_blog_comments WHERE entry='$id' ORDER BY timestamp";
    $result = mysql_query ($sql) or print ("Can't select comments from table php_blog_comments.
    ” . $sql . “
    ” . mysql_error());
    while($row = mysql_fetch_array($result)) {
    $timestamp = date(“l F d Y”, $row['timestamp']);
    printf(‘

    ‘);
    printf(“

    %s. On %s

    “, stripslashes($row['url']), stripslashes($row['name']), $timestamp);
    print(“

    ” . stripslashes($row['comment']) . “

    “);
    printf(“

    “);
    }

    ?>

    Name:




    < ?php $sql_prev = "SELECT * FROM php_blog WHERE id < '$id' ORDER BY id DESC LIMIT 1";
    $result_prev = mysql_query ($sql_prev) or print ("Can't select previous entry id table php_blog.
    ” . $sql_prev . “
    ” . mysql_error());

    while ($row = mysql_fetch_array($result_prev)) {
    $prev = $row['id'];
    }

    if (isset($prev)) {
    // print a previous link
    printf(“Previous “, $prev);
    }
    else {
    // just print the word “previous”

    print “Previous “; ?> |

    < ?php

    $sql_next = "SELECT * FROM php_blog WHERE id > ‘$id’ ORDER BY id LIMIT 1″;
    $result_next = mysql_query ($sql_next) or print (“Can’t select next entry id table php_blog.
    ” . $sql_next . “
    ” . mysql_error());

    while ($row = mysql_fetch_array($result_next)) {
    $next = $row['id'];
    }

    if (isset($next)) {
    // print a next link
    printf(“ Next“, $next);
    }
    else {
    // just print the word “next”

    print ” Next”;
    }
    } ?>

    < ?php include('footer.php'); ?>

    I’m really unsure on what do do, Michael. :roll:

    # April 9, 2010 at 4:17 pm

    I don’t know for sure. Is it possible that you don’t have permissions set up on the database for that user? does retro have full read, write access

    # April 11, 2010 at 2:27 am

    As cybershot said above, a "Access denied for user" error usually indicates either incorrect permissions or an incorrect database username or password. I’d double check your database login details and make sure they are correct.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".