Bob Howlett
Bob Howlett

Reputation: 33

PHP Mysqli - INSERT causes trailing commas in actual query

This has been driving me nuts all day - now I need some help please....

I have tried two ways to insert data into the database and both fail in ways i've not seen before!

Just using mysqli->query("...") - causes trailing commas at the end of the actual query as seen in the mysqld.general.log. There are as many extra commas as there are fields.

Using the mysqli->prepare method causes the actual prepare statement to appear in the log!

I include my code below along with what I see in the logs..

The global $mysqli object is created in an include file first - that definately works because select statements work fine...

Any help much appreciated.

CODE:-

function addplaces($placeID,$placename,$easting,$northing,$latitude,$longitude,$parish,$inuse,$shire)
{
 global $mysqli;

 $mysqli->query("INSERT INTO `places` (`placeID`,`placename`,`easting`,`northing`,`latitude`,`longitude`,`parish`,`inuse`,`shire`) VALUES ($placeID,$placename,$easting,$northing,$latitude,$longitude,$parish,$inuse,$shire)");

}

LOG OUTPUT:-

9594 Query INSERT INTO places (placeID,placename,easting,northing,latitude,longitude,parish,inuse,shire) VALUES ("12672","Accrington","375500","428500","53.752300262451","-2.3730099201202","Accrington","1",Lancashire,,,,,,,,) 9594 Quit

CODE:-

function addplaces($placeID,$placename,$easting,$northing,$latitude,$longitude,$parish,$inuse,$shire)
{
global $mysqli;
$stmt = $mysqli->prepare("INSERT INTO places (placeID,placename,easting,northing,latitude,longitude,parish,inuse,shire) VALUES (?,?,?,?,?,?,?,?,?)") or die ("Could not Prepare Statement");
$stmt->bind_param('sssssssss', $placeID,$placename,$easting,$northing,$latitude,$longitude,$parish,$inuse,$shire );
$stmt->execute();
}

LOG OUTPUT:-

9595 Prepare INSERT INTO places ( placeID, placename, easting, northing, latitude, longitude, parish, inuse, shire ) VALUES (?,?,?,?,?,?,?,?,?) 9595 Close stmt 9595 Quit

I have tried enclosing the Values fields in single and double quotes but still get the same result...

Also as this is my first post I'm not sure i've got the hang of this editor yet so please forgive me if I've got it wrong..

Upvotes: 1

Views: 429

Answers (1)

Clint Priest
Clint Priest

Reputation: 210

Looks to me like your $shire variable does not have quotes around it.

Upvotes: -1

Related Questions