PHP MySql INSERT

Discussion in 'PHP' started by emilfk, Jan 9, 2011.

  1. #1
    If the code in the tutorials worked, I would not be here.
    Please just help me to square one. And I will go do my peon thing.
    Hostgator MySql db, Access Host IP's are listed w/%, Appears to log on but will not Insert data.
    <?
    $user="emilfk_emilfk";
    $password="helpme";
    $database="emilfk_PRP";
    mysql_connect(localhost,$user,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    print "Connected to MySQL<br>";/*this msg does echo back, logged on Right?*/
    $query = "INSERT INTO fields VALUES ('','aaa','bbb','ccc','ddd','eee','fff','ggg')";
    mysql_query($query);
    $sql = "INSERT INTO `emilfk_PRP`.`Fields` (`id`, `first`, `last`, `phone`, `mobil`, `fax`, `email`, `web`) VALUES (NULL, \'aa\', \'bb\', \'cc\', \'dd\', \'ee\', \'ff\', \'gg\');";
    mysql_query($sql);
    mysql_query("INSERT INTO `emilfk_PRP`.`Fields` (`id`, `first`, `last`, `phone`, `mobil`, `fax`, `email`, `web`) VALUES (NULL, \'a\', \'b\', \'c\', \'d\', \'e\', \'f\', \'g\');");
    /* none of the above will write to db or give me an error, somebody please get me to square one*/
    mysql_close();
    ?>
    PHP:
    Thanks in advance
    Emil
     
    emilfk, Jan 9, 2011 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    add to the end of the query or die(mysql_error());

    so mysql_query('..'); becomes mysql_query('..') or die(mysql_error());

    try to do something yourselve, its easy to find out your errors! :)
     
    EricBruggema, Jan 9, 2011 IP
  3. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    #3
    I think the error is caused by the escaping of the single quotes. Because they are in double quotes, they don't need be be escaped.
     
    ssmm987, Jan 9, 2011 IP
  4. emilfk

    emilfk Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I came in with my hat in my hand.
    Could have done it without the condescending remark.
    Thanks
    Emil
     
    emilfk, Jan 9, 2011 IP
  5. ankit_frenz

    ankit_frenz Active Member

    Messages:
    1,111
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    63
    #5
    just a suggestion dont use this `emilfk_PRP`.`Fields` in case you decide to change DB your code will break :)
     
    ankit_frenz, Jan 9, 2011 IP