php insert

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by dianax8, Jan 24, 2015.

  1. dianax8

    dianax8 New Member

    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    I really hope you can help. I'm VERY new to php and I'm having trouble getting info to "insert" into my database. I have database created and I can insert manually in phpmyadmin, but not using php. I'm using:

    $con = mysql_connect("localhost","xxxxxxxxx","xxxxxxx")
    or die ("didn't work");// this works ok, cuz I run by itself and get check message at end

    mysql_select_db("fitforli_database",$con);//this also works ok

    //below is what won't work, I've tried with and without the MySQL_query command. do I need to use quotation marks throughout?
    mysql_query (INSERT INTO `fitforli_database`.`gym` (`id`, `fname`, `lname`, `address`, `city`, `state`, `phone`, `email`,
    `gender`, `contact`, `contact#`, `relation`, `plan`)
    VALUES (null, "test","test","test","test","test","test","test","test","test","test","test","test");
    echo ("ok");
     
  2. Dead-i

    Dead-i x10Hosting Support Ninja Community Support

    Messages:
    6,084
    Likes Received:
    364
    Trophy Points:
    83
    Hi dianax8,

    Your MySQL query needs to be wrapped in quotation marks, like this:
    Code:
    mysql_query('INSERT INTO `fitforli_database`.`gym` (`id`, `fname`, `lname`, `address`, `city`, `state`, `phone`, `email`, `gender`, `contact`, `contact`, `relation`, `plan`) VALUES(NULL, "test","test","test","test","test","test","test","test","test","test","test","test")');
    I've moved this thread to the Programming forum. :)
     
  3. ChatIndia

    ChatIndia Community Advocate Community Support

    Messages:
    1,407
    Likes Received:
    30
    Trophy Points:
    48
    first of all, don't use mysql_connect() because it's deprecated. Instead use Mysqli or PDO.
    second of all, mysql_query takes a String as it's first parameter. so you need to wrap your query in quotation marks.
     
  4. dianax8

    dianax8 New Member

    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    thanks , i'll try that
     

Share This Page