SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Nov 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Database Not Selected

    The error is "No database selected". However, there is nothing wrong with the name because the database "forms" exists. When I use the "test" database on phpMyAdmin, it works fine but it doesn't work on an identical database of a different name. I say it is identical because I copied the database in phpyMyAdmin so I could be mistaken.

    Here is my code:
    PHP Code:
    $con mysql_connect("localhost");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("forms"$con);

    $sql="INSERT INTO form_results (Name, Email, Subject, Message)
    VALUES
    ('
    $_GET[name]','$_GET[email]','$_GET[subject]','$_GET[message]')";

    if (!
    mysql_query($sql,$con))
      {
      die(
    'Error: ' mysql_error());
      }
    echo 
    "<p>Your record has been successfully added to the database.</p>";

    mysql_close($con); 

  2. #2
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you would need username and password...and whats about using the short method
    $con=mysql_connect('localhost','user','pass','dbname');
    plus do sanitize those get. Googling 'sql injection' might help.

    Thanks
    My personal suggestion dont try to start learning php as poetry rather first read other how they write it,that would help.(just a suggestion)

  3. #3
    SitePoint Member
    Join Date
    Nov 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Password in plain text

    Quote Originally Posted by frank1 View Post
    you would need username and password...and whats about using the short method
    $con=mysql_connect('localhost','user','pass','dbname');
    plus do sanitize those get. Googling 'sql injection' might help.
    Thanks that worked but I don't want to put the password in plain text inside the document. I think that's quite insecure and I wouldn't think that is normal behaviour.

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by goodthenks View Post
    Thanks that worked but I don't want to put the password in plain text inside the document. I think that's quite insecure and I wouldn't think that is normal behaviour.
    This is actually common practice. You're not supposed to have files such as these in the document root where they can be read by users. if your document root is /var/www/mysite/public, then you would want any php files with sensitive data stored somewhere such as /var/www/mysite/lib.


Tags for this Thread

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
  •