here my code-
$sql = "INSERT INTO tblpin ('pinId', 'ownerId', 'usedby', 'status') VALUES ";
for($i=0; $i<sizeof($pin); $i++)
{
if ($i>0)
{
$sql .= ", ";
}
$sql .= "('$pin[$i]', '$ownerid', 'Free', '1')";
}
$sql .= ";";
开发者_如何学编程
echo $sql;
mysql_query($sql);
if(mysql_affected_rows() > 0)
{
echo "done";
}
else
{
echo "Fail";
}
output: ** INSERT INTO tblpin ('pinId', 'ownerId', 'usedby', 'status') VALUES ('13837927', 'admin', 'Free', '1'), ('59576082', 'admin', 'Free', '1');
Fail
why it is not inserting values when $sql query is right?
here
INSERT INTO tblpin ('pinId', 'ownerId', 'usedby', 'status') VALUES
you got to use `` or use nothing to define table and rows but you cant use '' instead so the right query will be:
INSERT INTO `tblpin` (`pinId`, `ownerId`, `usedby`, `status`) VALUES ('13837927', 'admin', 'Free', '1'), ('59576082', 'admin', 'Free', '1');
OR:
INSERT INTO tblpin (pinId, ownerId, usedby, status) VALUES ('13837927', 'admin', 'Free', '1'), ('59576082', 'admin', 'Free', '1');
Don't put your column names between quotes.
INSERT INTO tblpin (pinId, ownerId, usedby, status) VALUES (13837927, 'admin', 'Free', 1), (59576082, 'admin', 'Free', 1);
精彩评论