On my site, there is a section called "My Ideal Board."
It is a form where the user will enter his data and there will be a return message with the ideal board type for the person.
First step, make form: Done;
Now I need to connect and register the data in the database. I created a table in the Wordpress database called "minhap". However, I am not able to register the data in it: confused:
The connection and registration code looks like this:
global $wpdb;
$nome = "";
$email = "";
$estilo = "";
$experiencia = "";
$altura = "";
$peso = "";
//VÁRIÁVEIS
if(!empty($_POST)){
$nome = $_POST['nome'];
$email = $_POST['email'];
$estilo = $_POST['estilo'];
$experiencia = $_POST['experiencia'];
$altura = $_POST['altura'];
$peso = $_POST['peso'];
cadastrar($nome,$email,$estilo,$experiencia,$altura,$peso);
calcularIMC($estilo,$experiencia,$altura,$peso);
}
function cadastrar($nome,$email,$estilo,$experiencia,$altura,$peso){ //INSERE OS DADOS NO BANCO
try{
$wpdb->prepare("INSERT INTO aa_minhaprancha("
. "nome, email, estilo, experiencia, altura, peso) VALUES("
. ":nome, :email, :estilo, :experiencia, :altura, :peso)");
$wpdb->bindValue(":nome", $nome);
$wpdb->bindValue(":email", $email);
$wpdb->bindValue(":estilo", $estilo);
$wpdb->bindValue(":experiencia", $experiencia);
$wpdb->bindValue(":altura", $altura);
$wpdb->bindValue(":peso", $peso);
$wpdb->execute();
if($wpdb->rowCount() > 0)
return true;
else
return false;
}catch(PDOException $e){
echo "Erro ao incluir na tabela categoria ".$e->getMessage();
}
}
At first, how can I connect and register data in the database?