Results 1 to 14 of 14

Thread: MYSQL Connections
      
   

  1. #1
    Skipper02 is offline Sergeant
    Join Date
    Jun 2008
    Posts
    25

    Default 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!!

  2. #2
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  3. #3
    Skipper02 is offline Sergeant
    Join Date
    Jun 2008
    Posts
    25

    Default 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

  4. #4
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  5. #5
    Skipper02 is offline Sergeant
    Join Date
    Jun 2008
    Posts
    25

    Default 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

  6. #6
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  7. #7
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  8. #8
    Skipper02 is offline Sergeant
    Join Date
    Jun 2008
    Posts
    25

    Default 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

  9. #9
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  10. #10
    Skipper02 is offline Sergeant
    Join Date
    Jun 2008
    Posts
    25

    Default 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 ?

  11. #11
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  12. #12
    Skipper02 is offline Sergeant
    Join Date
    Jun 2008
    Posts
    25

    Default 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!

  13. #13
    Skipper02 is offline Sergeant
    Join Date
    Jun 2008
    Posts
    25

    Default 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?

  14. #14
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49