I'm trying to call a PHP function in a separate PHP file from another PHP file. First is the shortened PHP file where I call the function, then there is the shortened PHP file with the method I'm trying to call.
require("./includes/themaDB.inc.php");
$themaDB = new ThemaDB($username, $passwd);
session_start();
$email = $_SESSION['e_mail'];
if(isset($_POST['titel']) && isset($_POST['kort']) && isset($_POST['lang'])){
$themaDB->voegThemaToe($titel, $kort, $lang, $email);
}
The code above gets called everytime the page loads.
class ThemaDB{
private $db;
public function __construct($user="root", $pwd="") {
$this->db = new PDO("mysql:host=localhost;dbname=cvranken",$user, $pwd);
}
public function getThemas(){
$stmt = $this->db->prepare("select * from thema");
$stmt->setFetchMode(PDO::FETCH_OBJ);
$stmt->execute();
$themas = array();
while($obj = $stmt->fetch()){
array_push($themas, $obj);
}
return $themas;
}
public function voegThemaToe($titel, $kort, $lang, $email){
$stmt = $this->db->prepare("insert into thema (titel, korte_omschrijving, lange_omschrijving, voorgesteld_door_docent_PK) values(:titel, :kort, :lang, :email)");
$stmt->bindParam(":titel", $titel);
$stmt->bindParam(":kort", $kort);
$stmt->bindParam(":lang", $lang);
$stmt->bindParam(":email", $email);
$stmt->execute();
}
}
This throws following fatal error.
Fatal error: Call to undefined method ThemaDB::voegThemaToe() in /home/jail/home/cvranken/public_html/docentThema.php on line 47
Line 47 in the real code is the one where I call voegThemeToe in the top code.
Sorry that some parameters are in Dutch :)
Aucun commentaire:
Enregistrer un commentaire