y3di
y3di

Reputation: 673

Inserting multiple rows in mysql php

I'm trying to insert multiple rows but I continue getting an sqlerror and cannot for the life of me figure out why.

    echo '"'.$thequery.'"';
    $sql = mysql_query($thequery) or die(mysql_error());
    return "SUCCESS";

$thequery gets printed out as: "INSERT INTO thistable (rank, change, reqID, vanID) VALUES (1,'PICKUP',28,1),(2,'PICKUP',29,1),(3,'DROPOFF',28,1),(4,'DROPOFF',29,1)"

and the 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 'change, reqID, vanID) VALUES (1,'PICKUP',28,1),(2,'PICKUP',29,1),(3,'DROPOFF',28' at line 1

Thanks in advanced.

Upvotes: 0

Views: 689

Answers (1)

glglgl
glglgl

Reputation: 91139

CHANGE is a reserved word in MySQL. Rename the column or enclose the identifier in backticks.

Besides, you seem to have a typo in the VALUES part: in (1,'PICKUP,'28,1),(2,'PICKUP,'29,1),, the ,' should be ',.

Upvotes: 1

Related Questions