2

Possible Duplicate:
Mysql can't perform more than 1 query at a time

        $query = "TRUNCATE TABLE nw_world;";
        $query = $query . " INSERT INTO `nw_world`";
        $query = $query . " SELECT * FROM `x_world` WHERE x <0 AND y >=0";
        $query = $query . " AND tid !=5 AND aid NOT IN ( 29, 908, 935, 941, 950 )";
        $query = $query . " AND population <=50";

        echo "$query";
        mysql_query($query,$con) or die("error ".mysql_error());

This results in an error

error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO `nw_world` SELECT * FROM `x_world` WHERE x <0 AND y >=0 AND tid !=5 ' at line 1

But when i execute the same query in mysql it works fine. Due to which i am having a feeling that i am making some mistake in the php coding. Please help

Community
  • 1
  • 1
debal
  • 997
  • 4
  • 15
  • 29

2 Answers2

3

mysql_query does not let you execute more than 1 query. Use mysqli::multi_query or execute each command separately.

a1ex07
  • 36,826
  • 12
  • 90
  • 103
3

PHP, by default, will only execute 1 query per mysql_query call (security measure).

If you want to execute more than one at a time look at http://se2.php.net/manual/en/mysqli.multi-query.php

Tom
  • 3,031
  • 1
  • 25
  • 33