0

I have this code.

elseif ($numerodeprocesos == 4) {
    $upd2= "INSERT INTO juan (ciudadh)
    VALUES ('$ciudadh')";
    $upd3= "INSERT INTO juan (ciudadh)
   VALUES ('$ciudadh')";
    $upd4= "INSERT INTO juan (ciudadh)
   VALUES ('$ciudadh')";
   $upd5= "INSERT INTO juan (ciudadh)
    VALUES ('$ciudadh')";
   $upd6= "INSERT INTO juan (ciudadh)
   VALUES ('$ciudadh')";
mysql_query($upd2)or die( mysql_error() );
mysql_query($upd3)or die( mysql_error() );
    mysql_query($upd4)or die( mysql_error() );
        mysql_query($upd5)or die( mysql_error() );
            mysql_query($upd6)or die( mysql_error() );

} 

But, what is the most simple way do to that? I mean it is possyble to do it in one single mysql_query?

Thanks in advance for your help

JuanFernandoz
  • 805
  • 17
  • 40
  • 2
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – Ja͢ck Feb 10 '13 at 04:21
  • [this page](http://dev.mysql.com/doc/refman/5.0/fr/insert.html) gives you the syntax for `INSERT` in mysql. – didierc Feb 10 '13 at 04:22
  • 1
    But all these insert the same variable `$ciudadh`, so why would you need to keep inserting the same values? Looks more like an over-writing code. – Javier Brooklyn Feb 10 '13 at 04:25
  • Yes, @Javier Brooklyn is just the same value. And I need over writing that same values for one specific reason into my code (its important to me). – JuanFernandoz Feb 10 '13 at 04:30

1 Answers1

3

This would be a single insert statement that inserts multiple rows:

INSERT INTO juan (ciudadh)
    VALUES ('$ciudadh'), ('$ciudadh'), ('$ciudadh'), ('$ciudadh');

See also: INSERT Syntax

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309