query excuting problem

Discussion in 'PHP' started by srini_r85, May 25, 2010.

  1. #1
    hi,

    i tried to execute following query in php script.

    
    $db_selected = mysql_select_db("lumiinc1_sndemo1", $con);
    
    if ($db_selected) {
    
    echo "database connected"; 
    }
    else
    {
      die ("Can\'t use db : " . mysql_error());
    }
    
    $sql = "INSERT INTO `markers` ( `name`, `address`, `lat`, `lng`, `id` ) SELECT `name`, `street`, `latitude`, `longitude`, `lid` FROM `location` WHERE NOT EXISTS ( SELECT * FROM `markers` WHERE `location`.`lid` = `markers`.`id` )";
      
    $result = mysql_query($sql); 
    
    if ($result) {
        echo "Query executed OK";
    } else {
        die("Invalid query: " . mysql_error());
    }  
    
    PHP:
    script does not show any error.also query executed.but i didn't get my expected result.at the same i try this query in phpmyAdmin i got my expected result. i dont know the cause of this problem.
    plz any one find the problem .
    thanks
     
    srini_r85, May 25, 2010 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    i think its on the mysql_error(), im not sure but why dont you try. mysql_query(your query) or die(mysql_error()); instead of putting it to condition statement if
     
    bartolay13, May 25, 2010 IP
  3. shubhamjain

    shubhamjain Active Member

    Messages:
    215
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #3
    INSERT INTO `markers` ( `name`, `address`, `lat`, `lng`, `id` ) SELECT `name`

    I am not sure if it is correct.
     
    shubhamjain, May 25, 2010 IP
  4. Lord

    Lord Active Member

    Messages:
    134
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    yes the sql is incorrect it should be something like

    INSERT INTO `markers` ( `name`, `address`, `lat`, `lng`, `id` ) VALUES (SELECT `name` ... )
     
    Lord, May 27, 2010 IP