i want to add an entrance (using a form) into a Mysql table using POO. Here is what i did : My class :
<?php
class portfolio{
public $title;
public $img_desk;
public $img_tablet;
public $img_phone;
public $id;
public function __construct($title, $img_desk, $img_tablet, $img_phone, $port_id){
$this->title = $title;
$this->img_desk = $img_desk;
$this->img_tablet = $img_tablet;
$this->img_phone = $img_phone;
$this->id = $port_id;
}
public function getPortfolio($id){
$reponse = $bdd->query('SELECT * FROM designer WHERE id = $id');
$portfolio = $reponse->fetch();
$a = new portfolio($portfolio['title'], $portfolio['img_desk'], $portfolio['img_tablet'], $portfolio['phone'], $portfolio['id']);
return $a;
}
public function addPortfolio($title, $img_desk, $img_tablet, $img_phone){
$add = $bdd->exec('INSERT INTO designer(title, img_desk, img_tablet, img_phone) VALUES(:title, :img_desk, :img_tablet, :img_phone)');
$add->execute(array( // _> was used.!!!
'title' => $title,
'img_desk' => $img_desk['name'],
'img_tablet' => $img_tablet['name'],
'img_phone' => $img_phone['name']
// imgs...
));
if (isset($img_desk) AND $img_desk['error'] == 0){
// Testons si le fichier n'est pas trop gros
if ($img_desk['size'] <= 3000000)
{
require("class/img.class.php");
// Testons si l'extension est autorisée
$infosfichier = pathinfo($img_desk['name']);
$extension_upload = $infosfichier['extension'];
$extensions_autorisees = array('jpg', 'jpeg', 'gif', 'png');
if (in_array($extension_upload, $extensions_autorisees))
{
// On peut valider le fichier et le stocker définitivement
move_uploaded_file($img_desk['tmp_name'], 'img/port/' . basename($img_desk['name']));
}
}
}
echo 'Élement ajouté';
}
public function editPortfolio($old, $new){
$edit = $bdd->prepare('UPDATE designer SET title = :title, img_desk = :img_desk, img_tablet = :img_tablet, img_phone = :img_phone WHERE id = $old->id ');
$edit->execute(array(
'title' => $new->title,
'img_desk' => $new->img_desk,
'img_tablet' => $new->img_tablet,
'img_phone' => $new->img_phone
));
}
public function deletePortfolio($cible){
//DELETE FROM designer WHERE id = $cible->id;
}
public function getAllPortfolio(){
//$reponse = $bdd->query('SELECT * FROM designer');
//$donnees = $reponse->fetch();
//return $donnees;
}
}
?>
And here is my using on a php file containing the form :
<?php
include('class/portfolio.class.php');
if(isset($_POST['title'])){
addPortfolio($_POST['title'], $_FILES['img_desk'], $_FILES['img_tablet'], $_FILES['phone']);
echo 'ok';
}else{
?>
<form method="post" action="admin.php" enctype="multipart/form-data">
<input type="text" placeholder="Titre" name="title"><br>
<input type="file" name="img_desk"><br>
<input type="file" name="img_tablet"><br>
<input type="file" name="img_phone"><br>
<input type="submit" value="Ajouter" name="ok">
</form>
<?php
}
?>
And it's telling me :
Fatal error: Call to undefined function addPortfolio() in C:\wamp\www\designers\admin.php on line 47
Would someone explain me please ? I know i'm doing things wrong but i'm actually learning OOP. Thank you in advance : ).