Need some basic help

Discussion in 'PHP' started by GrassR00ts, Feb 11, 2008.

  1. #1
    Hello All

    iam not great with PHP and such but i have a script thats trying to insert into my db. It used to work and then i got creatvie with it. I think i have an error somewhere in here

    $dbLink = mysql_connect($host, $username, $password);
    if(!$dbLink) die("Could not connect to database. " . mysql_error());

    mysql_select_db($dbname);

    mysql_query("INSERT INTO $table (id,name,email,category,title,article,tags,package,date) VALUES ('','$name','$email','$category','$title','$article','$tags','$package','$date')");


    in any case I was willing to pay for someones time to look over the file.

    Please pm me if you have a moment

    Thanks!
    Alex
     
    GrassR00ts, Feb 11, 2008 IP
  2. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Hi Alex

    Replace the query code with this and post the error that php gives:

    if (!mysql_query("INSERT INTO $table (id,name,email,category,title,article,tags,package,date) VALUES ('','$name','$email','$category','$title','$article','$tags','$package','$date')")) {
        die('Invalid query: ' . mysql_error());
    }
    PHP:
    Brew
     
    Brewster, Feb 11, 2008 IP
  3. GrassR00ts

    GrassR00ts Active Member

    Messages:
    614
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    58
    #3
    This is the error iam looking at


    Invalid query: No database selected


    Thanks for the help!
     
    GrassR00ts, Feb 11, 2008 IP
  4. GrassR00ts

    GrassR00ts Active Member

    Messages:
    614
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    58
    #4
    this is what was above that sql statement from before


    <?php
    $host ="localhost";
    $username="adfmeadia_orderad";
    $password="letmaein23";
    $dbname="adfmeddia_bnadmin";
    $table = "oneeidfght";

    $name = $_POST['Name'];
    $email = $_POST['Email'];
    $category = $_POST['category'];
    $title = $_POST['Title'];
    $article = $_POST['article'];
    $package = $_POST['package'];
    $date = date("F j, Y, g:i a");

    $name = htmlentities($name);
    $email = htmlentities($email);
    $title = htmlentities($title);


    $dbLink = mysql_connect($host, $username, $password);
    if(!$dbLink) die("Could not connect to database. " . mysql_error());

    mysql_select_db($dbname);


    So it seems like iam setting the db name
     
    GrassR00ts, Feb 11, 2008 IP