1
I made a registration form and an Insert query with Pdo, but when entering the data and pressing the button to call the query nothing happens, no error messages appear, nor in the log, there is something wrong in the codes ? ;-;
Query Insert
class Cadastro {
private $con;
private $serial;
private $login;
private $email;
private $rrname;
private $senha;
private $nome;
public function __construct() {
$this->con = new Conexao();
}
public function queryInsert($dados) {
try {
$this->login = $dados['login'];
$this->senha = sha1($dados['senha']);
$this->email = $dados['email'];
$this->rrname = $dados['rrname'];
$cst = $this->con->conectar()->prepare("INSERT INTO 'contas' ('login', 'senha', 'email', 'nomenorr') VALUES (:login, :senha, :email, :rrname)");
$cst->bindParam(':login', $this->login);
$cst->bindParam(':senha', $this->senha);
$cst->bindParam(':email', $this->email);
$cst->bindParam(':rrname', $this->rrname);
if ($cst->execute()) {
return 'sucess';
} else {
return 'error';
}
} catch (PDOException $ex) {
}
}
Connection class
<?php
class Conexao {
private $servidor;
private $banco;
private $user;
private $password;
private static $pdo;
public function __construct() {
$this->servidor = "localhost";
$this->banco = "rrcard";
$this->user = "root";
$this->password = "12345";
}
public function conectar() {
try {
if (is_null(self::$pdo)) {
self::$pdo = new PDO("mysql:host=" . $this->servidor . ";bdname" . $this->banco, $this->user, $this->password);
}
return self::$pdo;
} catch (PDOException $ex) {
}
}
}
php of the htm page
<?php
require_once '/src/domain/conta.php';
$Cad = new Cadastro();
if (isset($_POST['btCad'])) {
if ($Cad->queryInsert($_POST) == 'sucess') {
header("location: ./index.php");
} else {
header("location: ./cadastro.php");
}
}
?>
Html registration form
<form method="POST" action="">
Login:<br>
<input type="text" name="login" class="campo" maxlength="40" required autofocus><br>
Senha:<br>
<input type="password" name="senha" class="campo" maxlength="40" required><br>
Email:<br>
<input type="email" name="email" class="campo" maxlength="50" required><br>
Nome no RR:<br>
<input type="text" name="rrname" class="campo" maxlength="40" required><br>
<br><br>
<input type="submit" name="btCad" value="Confirmar" class="btn">
<br><br>
<input type="checkbox" value="check" required>
Ao criar a conta você confirma que leu e concorda com os nossos <a id="terms" class="terms" href="#"> termos de uso </a>
</form>
you don’t even have a button calling the action="/aquivoParaExecutarOMetodo" <button type="Submit">save</button>
– André Martins
But the button that is there is already being called in php code, so I don’t need to put a path in the action=", no ?
– Vazafirst
Have you ever considered displaying a message when an exception is captured? You capture the exception and do nothing with it.
– Woss