0
This is the form to enter data
<html>
<head>
<title></title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<form action="cadastrando.php" method="POST">
<input type="text" name="nome"><br><br>
<input type="text" name="idade"><br><br><br>
<input type="radio" name="sex" value="male"> Masculino
<br>
<input type="radio" name="sex" value="female"> Feminino<br>
<input type="text" name="email">
<input type="password" name="senha"><br><br>
<input type="text" name="peso"><br><br>
<input type="text" name="altura"><br>
<input type="text" name="qntd_exe">
<input type="submit" value="Cadastrar">
</form>
</body>
</html>
And this here is the data reader with the command to enter the data
<?php
$link = mysqli_connect("localhost", "root", "", "tcc");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
?>
<html>
<head>
<title></title>
<meta charset="utf-8">
</head>
<body>
<?php
$nome = $_POST['nome'];
$idade = $_POST['idade'];
$email = $_POST['email'];
$senha = $_POST['senha'];
$peso = $_POST['peso'];
$altura = $_POST['altura'];
$imc = ($peso/($altura*$altura));
$qntd_exe = $_POST['qntd_exe'];
$sql = "INSERT INTO usuario VALUES ";
$sql .= "($nome', '$idade', '$email', '$senha', '$peso', '$altura', '$imc', '$qntd_exe', '$sexo')";
mysqli_query($link,$sql) or die("Erro ao tentar cadastrar registro");
mysqli_close($link);
echo "Cliente cadastrado com sucesso!";
?>
</body>
</html>
As much as I search and change several codes it does not appear error, but also does not insert the data in B.D
If you do not define the column names in the clause
insert
, you need to define the value of all of them, including theid
.– Woss
Here is a simple example: https://wiki.locaweb.com.br/pt-br/Formul%C3%A1rio_php_%2B_Mysql .
– Emerson Vieira
I’ll take a look, thank you very much!
– Felipe Moreno Borges
Ah, but if the id is auto increament as I leave it at the time of inserting? empty?
– Felipe Moreno Borges
If you do not specify column names, you do. In this case, simply put the value as
default
.– Woss
do not need to put the id referring to the query I suggested INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
– user60252