MYSQL Connections

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Skipper02
    Sergeant

    • Jun 2008
    • 25

    MYSQL Connections

    I am unable to connect to my database. I have put the following code in a html box in my form page but it is not working. I am getting the error message HTTP 404. The code that I am using to connect to my database is as follows;

    <?php
    $db_host= "localhost";
    $db_username = "YYYY_XXXXX";//where YYYY is my CP username and XXXXX is my database username
    $db_password = "ZZZZZ"
    $dbname ="YYYY_StudyKitchenData";
    $conn = mysql_connect($db_host,$db_username,$db_password);
    mysql_select_db($dbname);
    close($conn);
    ?>


    Please help!!
  • navaldesign
    General & Forum Moderator

    • Oct 2005
    • 12080

    #2
    Re: MYSQL Connection Problem - Please help

    404 error message has nothing to do with the database connection. Probably you have mistyped the page URL or you are trying to see a html page whilst it is php or viceversa.

    A link would be usefull to see what your problem is.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment

    • Skipper02
      Sergeant

      • Jun 2008
      • 25

      #3
      Re: MYSQL Connection Problem - Please help

      Navaldesign, thanks for taking the time to look into my problem. Earlier when I was saving the page as *.bvp or *.php, I was getting the HTTP 404 error message. After reading your post, I saved the page as *.html and I did not get the error message but still the echo statements are not printing on the screen so I am not sure if the script is getting executed or not.

      I embedded the script by going into View -->Page HTML ---> Inside body tag.

      The link is http://www.studykitchen.com/test4.html

      Also just for my knowledge, shouldn't I be saving the page as .bvp or .php instead of .html if I have embedded php code in the page?

      Regards
      Skipper

      Comment

      • navaldesign
        General & Forum Moderator

        • Oct 2005
        • 12080

        #4
        Re: MYSQL Connection Problem - Please help

        The page is always saved simply as "pagename" WITHOUT any extension. The extension is generated by BV when it publishes the page. If the page contains php code, you need to publish it as php page. This is done setting, in Page Properties, the page extension ( when published) to be php instead of the standard html.

        Now, your test4 page is html, so it can never execute the php code embedded in the page.

        A further issue: your code (which i can see because the page is html, and not php):

        <?php
        echo("Success 1");
        $db_host= "localhost";
        $db_username = "tuwipwa_?????????";
        $db_password = "Krishna 1965"
        $dbname ="tuwipwa_Study???????????";
        echo("Success 2");
        $conn = mysql_connect($db_host,$db_username,$db_password);
        mysql_select_db($dbname);
        echo("Success 3");
        close($conn);
        echo("Success 4");
        ?>

        will do nothing (when executed). I mean, it opens a DB connection and then it closes it, without doing anything at all.
        The only output will be those echoes "Success 1" ..... to "Success 4" but nothing more.

        Usually, after you open the connection, you query a specific table in the database, to retrieve some info (or add, or edit) and display it in your page. In this case you do nothing of the above.
        Navaldesign
        Logger Lite: Low Cost, Customizable, multifeatured Login script
        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

        Comment

        • Skipper02
          Sergeant

          • Jun 2008
          • 25

          #5
          Re: MYSQL Connection Problem - Please help

          Navaldesign thanks once again and sorry to bug you yet once more. I saved the page by changing the setting in page properties, as suggested by you, so it executed but this time it gave a syntax error:

          Parse error: syntax error, unexpected T_VARIABLE in /home/tuwipwa/public_html/test5.php on line 13

          I used the same code as I had used earlier and removed a blank line so if you refer to my earlier code the error will be in line 14.

          The echo statements didn't print, probably because of the syntax error.

          Well I understand, I have not written any queries so the page won't do anything else besides printing the echo statements but before going further I wanted to check the connection because normally this is the biggest issue I generally have but in BlueVoda it appears much simpler than in many other web hosting packages.

          Please let me know what is causing the syntax error.

          Thanks
          Skipper

          Comment

          • navaldesign
            General & Forum Moderator

            • Oct 2005
            • 12080

            #6
            Re: MYSQL Connection Problem - Please help

            in test5.php i only see a message about access denied to the user. It is not enough creating user and pas, you ned to ADD this user to the specific database (in CP, MySQL section). Did you ?
            Navaldesign
            Logger Lite: Low Cost, Customizable, multifeatured Login script
            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

            Comment

            • navaldesign
              General & Forum Moderator

              • Oct 2005
              • 12080

              #7
              Re: MYSQL Connection Problem - Please help

              And, you do have a mistake in your code in the second part. Replace your code with this:

              <?php
              echo("Success 1");
              $db_host= "localhost";
              $db_username = "tuwipwa_?????????";
              $db_password = "Krishna 1965";
              $dbname ="tuwipwa_Study???????????";
              $db = mysql_connect($db_host, $db_user, $db_password);
              if ($db == FALSE){
              $error = "Could not connect to the Database Server. Please check user details. Error = ". mysql_error();
              exit($error);
              }
              echo "Completed DB connection";
              mysql_select_db($db_name, $db);
              if (!mysql_select_db($db_name, $db)) {
              $error = "Could not select Database. Please check user details. Error = ". mysql_error();
              exit($error);
              }
              echo "Completed DB selection";
              // Your query here
              mysql_close($db);
              ?>

              The problem you were getting was the missing ";" in the $db_username = .......... line
              Navaldesign
              Logger Lite: Low Cost, Customizable, multifeatured Login script
              Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
              DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
              Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

              Comment

              • Skipper02
                Sergeant

                • Jun 2008
                • 25

                #8
                Re: MYSQL Connection Problem - Please help

                Yes, I did. Now the page is not showing any access denial message but still it is not printing the echo statements which it should. What am I doing wrong? I am already feeling pretty stupid

                Comment

                • navaldesign
                  General & Forum Moderator

                  • Oct 2005
                  • 12080

                  #9
                  Re: MYSQL Connection Problem - Please help

                  Your messages (success 1 etc) displays ok. BUt it is in WHITE color. So you can't see it.
                  Look at the page code to see it.
                  Navaldesign
                  Logger Lite: Low Cost, Customizable, multifeatured Login script
                  Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                  DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                  Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                  Comment

                  • Skipper02
                    Sergeant

                    • Jun 2008
                    • 25

                    #10
                    Re: MYSQL Connection Problem - Please help

                    Navaldesign, a big THANK YOU to you!! We are getting closer. I used your code snippet and got the following error message:

                    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'tuwipwa'@'localhost' (using password: YES) in /home/tuwipwa/public_html/test8.php on line 14
                    Could not connect to the Database Server. Please check user details. Error = Access denied for user 'tuwipwa'@'localhost' (using password: YES)

                    As you suggested, I checked andI do have the user added to the database. So what else could possibly prevent denial of access ?

                    Comment

                    • navaldesign
                      General & Forum Moderator

                      • Oct 2005
                      • 12080

                      #11
                      Re: MYSQL Connection Problem - Please help

                      Sorry, my mistake. In my code it is $db_user, in yours it is $db_username. Also you had $dbname, i had $db_name . Edit the connection details lines:

                      $db_host= "localhost";
                      $db_user = "tuwipwa_?????????";
                      $db_password = "Krishna 1965";
                      $db_name ="tuwipwa_Study???????????";
                      Navaldesign
                      Logger Lite: Low Cost, Customizable, multifeatured Login script
                      Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                      DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                      Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                      Comment

                      • Skipper02
                        Sergeant

                        • Jun 2008
                        • 25

                        #12
                        Re: MYSQL Connection Problem - Please help

                        Thank you, General. I salute to your expertise and for guiding me through this problem. I think its working now. Thanks again!

                        Comment

                        • Skipper02
                          Sergeant

                          • Jun 2008
                          • 25

                          #13
                          Re: MYSQL Connection Problem - Please help

                          Navaldesign, the last code you gave is executing fine but the echo statements are still not visible in the browser. What setting do I need to change to make the echo statements visible in the browser?

                          Comment

                          • navaldesign
                            General & Forum Moderator

                            • Oct 2005
                            • 12080

                            #14
                            Re: MYSQL Connection Problem - Please help

                            Remove the code from the body of the page. Place it either in a html box (this way you can control also the position where the echo statements will appear) or in the Start of page (the text will appear on the very top).
                            Navaldesign
                            Logger Lite: Low Cost, Customizable, multifeatured Login script
                            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                            Comment

                            Working...
                            X