SitePoint Sponsor

User Tag List

Results 1 to 24 of 24
  1. #1
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)

    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'


    Ignoring that "dbselect" for now, this is my code.

    config.php
    PHP Code:
    <?php$host="localhost";
    $username="ryanree1_reese";
    $password="*************";
    $tableName="userSubmitted";
    $DbName="blog";

    ?>

    checkInfo.php
    PHP Code:
    <?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>


    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.
    Last edited by SpacePhoenix; Feb 27, 2012 at 00:40. Reason: put php tags around php code
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    This is not my area at all, but I notice you don't have a gap between ?php and $host here:

    PHP Code:
    <?php$host="localhost";
    I'm pretty sure there should be a gap there.

  3. #3
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    It's just from copy pasting.
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Well, there's meant to be a space after <?php, so give it a try!

  5. #5
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Did I not just say it's from copy pasting?

    The file has a line break...
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by RyanReese View Post
    Did I not just say it's from copy pasting?
    Yes, but it didn't mean anything.

  7. #7
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Yes, but it didn't mean anything.
    It does if you wonder why that was my response to your statement .
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  8. #8
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by RyanReese View Post
    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.

    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: <?phpsession_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.

  9. #9
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    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 .
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  10. #10
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,184
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    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.
    The only code I hate more than my own is everyone else's.

  11. #11
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    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.
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  12. #12
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    did you give access rights for your user? By default they have no rights...
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  13. #13
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    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?
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  14. #14
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    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.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  15. #15
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  16. #16
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,883
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Just posted and noted that others have answered with the same permission possible answers.

    Deleting post
    Last edited by John_Betong; Feb 27, 2012 at 09:33. Reason: syntax error
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  17. #17
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    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.
    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.
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  18. #18
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    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());
    }
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  19. #19
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    K, now a new error.

    Code:
    <?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 "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"
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  20. #20
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    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.
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  21. #21
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,883
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    For debugging purposes I use the following:

    PHP Code:

      
    # content should be validated to prevent GIGO
      
    $contentOfPost = isset( $_POST['contentOfPost'] ) ? $_POST['contentOfPost'] : FALSE;

      if ( ! 
    $contentOfPost && $submit != $_POST['submit'] )
      {
        echo 
    '<pre>';
           
    print_r$_POST );
        echo 
    '</pre>';
        die;
      }
      else
      {
        
    $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);
        
    # check your SQL on error
        
    if ( ! $result )
        {
           echo 
    $insertionToDatabase;
           echo 
    '<br />';
           die( 
    'Invalid query: ' mysql_error() );
        }
        echo 
    $result;
        
    mysql_close($link);
      }
    //endelse
    ?> 
    Also, check your table Field type, Defaults and Attributes and let the database do all the work
    # Field Type => TIMESTAMP
    # Default => CURRENT _TIMESTAMP
    # Attributes => on update CURRENT_TIMESTAMP
    Last edited by John_Betong; Feb 27, 2012 at 18:50. Reason: added missing square bracket
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  22. #22
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Yes the time field in my database is correct. It matches what you wrote down for me to have.

    As for that code, what am I replacing it with? I posted a new thread describing my issue along with my full code.
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  23. #23
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,883
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    @RyanReese

    Yes the time field in my database is correct. It matches what you wrote down for me to have.

    As for that code, what am I replacing it with? I posted a new thread describing my issue along with my full code.
    If the time field is set to TIMESTAMP then changing the Default and Attributes in the table structure field dropdowns eliminate the need to pass the date and current time on updates.

    PHP Code:
       #  Defaults inserted for PostNumber, Date, Time 
       
    $insertionToDatabase"INSERT INTO $tableName   (  Content )  VALUES  ( $contentOfPost )"

    As for that code, what am I replacing it with? I posted a new thread describing my issue along with my full code.
    On errors encountered the code I posted displays more informative error messages.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  24. #24
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,726
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I changed the attributes to "null"

    And ok thanks for the debugging tools .
    Always looking for web design/development work.
    http://www.CodeFundamentals.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •