Today I am trying to upload data from a registration form to my db using PDO, I get "Error" which is the return that I have established when sending data.
<?php
require_once('models/connection.php');
class Data extends Connection {
public function RegisterUserModel($dataModel, $table) {
#Preparando conexion a la base de datos.
$stmt = Connection::connect()->prepare("INSERT INTO $table(user, pass, email) VALUES (:user,:password,:email)");
#Vinculando parametros a los valores que se almacenarán en la base de datos.
$stmt->bindParam(":user", $dataModel["user"], PDO::PARAM_STR);
$stmt->bindParam(":password", $dataModel["pass"], PDO::PARAM_STR);
$stmt->bindParam(":email", $dataModel["email"], PDO::PARAM_STR);
#Ejecutando el registro del usuario en la base de datos.
if($stmt->execute()){
return "Succes";
} else {
return "Error";
}
}
}
?>
this is the connection.php file:
<?php
class Connection {
public function connect() {
$link = new PDO("mysql:localhost;dbname=encomienda;","root","");
return $link;
}
}
?>
and this is the controller.php file where the form data is sent:
<?php
class MvcController {
public function view(){
include('view/login.view.php');
}
public function LinkPagesController() {
if(isset($_GET['action'])){
$linkcontroller = $_GET['action'];
} else {
$linkcontroller = "index";
}
$request = LinkPageClass::LinkPagesModel($linkcontroller);
include $request;
}
public function RegisterUserController() {
if(isset($_POST["user"])) {
$dataController = array("user"=>$_POST["user"],
"pass"=>$_POST["password"],
"email"=>$_POST["email"]);
$request = Data::RegisterUserModel($dataController, "user");
echo $request;
}
}
}
?>