php
INSERT mvc OOP
<?php
//index.php
if(isset($_POST['submit'])){
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$obj = new Control(); // assign the object for controller class
$obj->insert($firstname,$lastname,$email); // Pass the data in insert function
//header("location: classes/control.class.php");
echo "<script>alert('Inserted')</script>";
echo "<script>window.open('index.php','_self')</script>";
}
?>
<?php
//control.class.php
class Control extends Model {
public function insert($firstname,$lastname,$email) {
$obj = new model();
$obj->createUser($firstname,$lastname,$email);
}
}
?>
<?php
//model.class.php
class Model extends Dbh{
protected function createUser($firstname,$lastname,$email) {
$sql = 'INSERT INTO users (firstname,lastname,email) VALUES (?,?,?)';
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$firstname,$lastname,$email]);
}
}
INSERT using OOP and MVC model
Was this helpful?
Similar Posts