I just installed the latest version of WordPress and created a page with a simple form.
<form class="" method="post" action="insert.php">
<input name="name" placeholder="Name">
<input name="email" placeholder="E-Mail">
<input name="company" placeholder="Company">
<button name="submit" type="submit">OK</button>
</form>
I would then like to insert the data from this form into a database table. I researched and found that a possible code to do this would be:
<?php
if(isset($_POST['submit']))
{
global $wpdb;
$wpdb->insert
('users', // Nome da tabela no banco de dados.
array
(
'name'=>$_POST['name'],
'email'=>$_POST['email'],
'company'=>$_POST['company'],
'registration'=>now()]
)
);
echo 'Usuário inserido com sucesso!'
}
?>
The questions would be:
Should I insert this code just below the form code or save everything to an external file?
And if that is the case, where should I save the insert.php file so that it is rotated by clicking the submit button?