gauche23
gauche23

Reputation: 67

mysql_query executes only once when looping - php

I have some code that will automatically assign a certain number of plates when entered in the field $num_plates. However, when looping the mysql_query only works once:

$region = $_POST['region'];
$num_plates = $_POST['num_plates']; //4

$prfx = 'AAA';
$sffx = '1001';
$c = 1;

while($c <= $num_plates) 
{
    $prfx = ++$prfx;
    $sffx = ++$sffx;

    mysql_query("INSERT INTO v_info (`plate_prefix`, `plate_suffix`, `region`, `status`) 
                 VALUES ('$prfx', '$sffx', '$region', 'Available')");

    $c = $c+1;
    echo "<h1 align='center'>".$c."</h1>";
}

Upvotes: 0

Views: 58

Answers (1)

Nathaniel Ford
Nathaniel Ford

Reputation: 21220

Multiple queries are explicitly not supported by mysql_query. From the manual:

mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.

On the other hand, mysqli does support multiple queries. You need to use that.

Upvotes: 1

Related Questions