SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I cant access my database through php?

    I am learning PHP and MySQL through tutorials, and now i am stucked at a point. In this i have to access my database using created php file, but after running error occurs,

    SQL error: Access denied for user ''@'localhost' (using password: NO)

    This means i am not providing username and password, but i dont know how do i provide it through php file ? Please help

    Code :

    ******* form.php **********
    PHP Code:
    <form method="post" action="user.php"
    <
    p><b>User ID:</b> <input type="text" name="userid" /></p
    <
    p><input type="submit" value="Search" /></p
    </
    form
    --------------------------------------

    ********* User.php ************
    PHP Code:
    <?php 
         import_request_variables
    ("pg""form_"); 

         
    $db mysql_connect("localhost:/export/mysql/mysql.sock"); 
         
    mysql_select_db("forum"$db); 
         
    $sql "SELECT name, email" 
              
    " FROM Users" 
              
    " WHERE userid = '$form_userid'"
         
    $rows mysql_query($sql$db); 
         if(!
    $rows) { 
              
    $error "SQL error: " mysql_error(); 
         } elseif(
    mysql_num_rows($rows) == 0) { 
              
    $error "No such user name found"
         } else { 
              
    $error FALSE
              
    $user_name mysql_result($rows00); 
              
    $user_email mysql_result($rows01); 
         } 
    ?> 
    <html> 
    <head> 
    <title>User information</title> 
    </head> 

    <body> 
    <?php 
          
    if($error) { 
               echo 
    "<h1>Error accessing user information</h1>\n"
               echo 
    "<p>$error</p>\n"
          } else { 
               echo 
    "<h1>Information about $form_userid</h1>\n"
               echo 
    "<p>User ID: <tt>$form_userid</tt></p>\n"
               echo 
    "<p>Real name: $user_name</p>\n"
               echo 
    "<p>E-mail address: <tt>$user_email</tt></p>\n"
          } 
    ?> 
    </body> 
    </html>
    Last edited by SpacePhoenix; Jul 7, 2011 at 09:47. Reason: put php tags around php code

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The username and password are the second and third arguments to mysql_connect

    PHP Code:
    $db mysql_connect("localhost""somuser""somepassword"); 

  3. #3
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now it says,

    SQL error: Access denied for user 'admin'@'localhost' (using password: YES)

    So what do i do now ???

  4. #4
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this
    $link = mysql_connect("localhost","root","");


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
  •