致命错误:在插入数据库时​​调用成员函数bind_param()

时间:2016-02-19 22:18:54

标签: php

我试图将数据插入数据库。但我收到一个错误,说我的绑定参数不正确。我试过更改绑定参数,但它没有什么区别。

<?php
ini_set('display_errors', 1);
require('../../../../includes/conn.inc.php');
require('../includes/functions.inc.php');
// sanitize user variables
$sFixtureName = safeString($_POST['fixtureName']);
$sFixtureDate =  safeString($_POST['fixtureDate']);
$sFixtureTime = safeFloat($_POST['fixtureTime']);
$sFixtureStadium = safeString($_POST['fixtureStadium']);
$sFixtureImage = safeString($_POST['fixtureImage']);
$sMatchInfoHome = safeString($_POST['matchInfoHome']);
$sMatchInfoAway = safeString($_POST['matchInfoAway']);
$sStadiumImage = safeString($_POST['stadiumImage']);
$slat = safeFloat($_POST['lat']);
$slng = safeFloat($_POST['lng']);
// prepare SQL
$stmt = $mysqli->prepare("INSERT INTO matchFixtures (fixtureName,fixtureDate,fixtureTime,fixtureStadium,fixtureImage,matchInfoHome,matchInfoAway,stadiumImage,lat,lng,) VALUES(?, ?, ?, ? ,?,?, ?, ?, ?,?)");
$stmt->bind_param('ssdsssssdd', $sFixtureName,
$sFixtureDate,
$sFixtureTime,

$sFixtureStadium,
$sFixtureImage,
$sMatchInfoHome,
$sMatchInfoAway,
$sStadiumImage,
$slat,
$slng);
$stmt->execute();
$stmt->close();
header("Location: ../index.php");
// redirect browser
exit; // make sure no other code executed
?>

1 个答案:

答案 0 :(得分:1)

$stmt = $mysqli->prepare("INSERT INTO matchFixtures (fixtureName,fixtureDate,fixtureTime,fixtureStadium,fixtureImage,matchInfoHome,matchInfoAway,stadiumImage,lat,lng,) VALUES(?, ?, ?, ? ,?,?, ?, ?, ?,?)");

应该是

$stmt = $mysqli->prepare("INSERT INTO matchFixtures (fixtureName,fixtureDate,fixtureTime,fixtureStadium,fixtureImage,matchInfoHome,matchInfoAway,stadiumImage,lat,lng) VALUES(?, ?, ?, ? ,?,?, ?, ?, ?,?)");

您在字段列表中有一个额外的逗号