Recently I started an echo mysql table for contacts, and now I need a button to add a new contact. I tried a lot of things, and that was my result (keep in mind that everything is located at the same file):
PHP:
//create record
if (isset($_POST['submitc'])) {
$empresa = $_POST['empresa'];
$contato = $_POST['contato'];
$telefone = $_POST['telefone'];
$email = $_POST['email'];
$sql = $conn->query("INSERT INTO Contacts (empresa, contato, email, phone)
VALUES ('$_POST[empresa]', '$_POST[contato]', '$_POST[telefone]',
'$_POST[email]')");
if(!$sql) {
echo ("Could not create" .mysqli_error());
}
}
Form:
<form method=post>
<div class='input-field'>
<i class='material-icons prefix'>work</i>
<input id='first_name' name='empresa' type='text' class='validate'>
<label for='first_name'>Empresa</label>
</div>
<div class='input-field'>
<i class='material-icons prefix'>account_circle</i>
<input id='first_name' name='contato' type='text' class='validate'>
<label for='first_name'>Contato</label>
</div>
<div class='input-field'>
<i class='material-icons prefix'>phone</i>
<input id='first_name' name='telefone' type='text' class='validate'>
<label for='first_name'>Telefone</label>
</div>
<div class='input-field'>
<i class='material-icons prefix'>email</i>
<input id='first_name' name='email' type='text' class='validate'>
<label for='first_name'>E-mail</label>
</div>
</form>
</div>
<div class='modal-footer'>
<button class='green darken-4 waves-effect waves-light btn' type='submit'
name='submitc' value='Add'>Criar</button>
</form>
As you can see in the PHP Part, I already tried a lot of things like using vars, $_POST but when I click the submit button, nothing happens, not even an error telling me something. Note that I'm trying to add value to all the 4 columns I have. What is wrong here?
(Please ignore these divs, i'm using Materialize, that's just CSS)
emailandphonecolumns in the query where you've switched them in the values.</form>doing there? You closed the form before the submit button.... <label for='first_name'>E-mail</label></div></form>, can you see this closing form tag right after the email input field? This is why your submit button is not working.