以下是错误日志: -
PHP Parse错误:语法错误,意外'deleteBike'(T_STRING), 期待'('在第126行的/var/www/html/page/db.php中,引用者: http://localhost/page/adminpage/intro.html [1月17日星期三20:29:17.889348 2018]
下面是我的db.php:
//add bike
static function addBike($mysqli, $bicycle_type,$station_id){
if ($stmt = $mysqli->prepare('INSERT INTO bicycle (bicycle_type, station_id) VALUES (?, ?)')){
$stmt->bind_param('si', $bicycle_type, $station_id);
if ($stmt->execute()){
return true;
} else {
return false;
}
}
//delete bike
static function deleteBike($mysqli,$bicycle_id){
if($stmt = $mysqli->prepare('DELETE FROM bicycle WHERE bicycle_id = ?')){
$stmt->bind_param('i',$bicycle_id);
if($stmt->execute()){
return true;
}else{
return false;
}
}
}
以下是来自updateBike.php:
// if the method is POST
if ($_POST){
$bicycle_type = $_POST['bicycle_type'];
$station_id = $_POST['station_id'];
if (Db::addBike($mysqli, $bicycle_type, $station_id)){
echo 'success!';
}
}
以下是来自intro.html:
<form method="post" action="updateBike.php"
<input type="text" name="bicycle_type">
<input type="number" name="station_id">
<input type="submit" value="Submit">
</div>
</form>
根据错误日志,deletebike()
出现了一些错误,但我甚至无法调用addbike()
事件{h} deleteBike()
是上面提到的错误。
我已经尝试了2个小时,我知道我错过了一些简单的错误,但我无法弄明白。非常感谢您的帮助。 :)
答案 0 :(得分:1)
我认为您错过}
来正确关闭addBike
方法(}
之前的deleteBike
是关闭第一个addBike
if语句的{{1}} )
答案 1 :(得分:0)
函数addBike不是很好,你已经关闭了函数:
static function addBike($mysqli, $bicycle_type,$station_id){
if ($stmt = $mysqli->prepare('INSERT INTO bicycle (bicycle_type, station_id) VALUES (?, ?)')){
$stmt->bind_param('si', $bicycle_type, $station_id);
if ($stmt->execute()){
return true;
} else {
return false;
}
}
}