-1

Below is error log :-

PHP Parse error: syntax error, unexpected 'deleteBike' (T_STRING), expecting '(' in /var/www/html/page/db.php on line 126, referer: http://localhost/page/adminpage/intro.html [Wed Jan 17 20:29:17.889348 2018]

Below is my 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;
            }
        }
    }

Below is from 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!';
                } 

        }

Below is from 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>

Based on the error log, deletebike() has some error but I cannot even call addbike() eventhough deleteBike() is the one got error stated above. I have been trying this for 2 hours, I know that I miss some simple mistake but I cannot figure it out. Your help will be much appreciated. :)

mmvsbg
  • 3,570
  • 17
  • 52
  • 73

2 Answers2

1

I think you are missing a } to properly close addBike method (the last } before deleteBike is the one closing the first addBike if statement)

giorrrgio
  • 66
  • 5
0

The function addBike not is well formed, you have close the function:

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;
        }
    }
}