JuanFernandoz
JuanFernandoz

Reputation: 799

Most simple way to make an multiple INSERT on PHP

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

Upvotes: 0

Views: 118

Answers (1)

Ja͢ck
Ja͢ck

Reputation: 173572

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

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

See also: INSERT Syntax

Upvotes: 4

Related Questions