Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    database connectivity problem

    I used the following code for inserting form data into "userinfo" table of "user" database.The database and table was created on xampp(phpmyadmin).But the page displayed "Error: No database selected".... why?pls help..


    <?php
    $con = mysql_connect("localhost","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("user",$con);

    $sql="INSERT INTO userinfo(id,pass)
    VALUES
    ('$_POST[UID]','$_POST[pass]')";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "1 record added";

    mysql_close($con);
    ?>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Try
    PHP Code:
    mysql_select_db("user",$con) or die(mysql_error()); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Apr 2010
    Posts
    55
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Wasn't that obvious? You have error checking everywhere, except on line where it select the db. The error message clearly says "Error: No database selected"

    Should be a wrong database name or the user have no rights on database mentioned.
    Hosting Reviews and Discounts: Bluehost Coupon and Hostmonster Coupon


  •  

    Tags for this Thread

    Posting Permissions

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