0
Hello
I have the following code and the information does not save in my database. Can someone help me?
<?php
$servername = 'localhost';
$username='root';
$password=null;
$dbname='task3';
$connect = mysqli_connect($servername,$username,$password,$dbname);
// verifica a conexao
if (mysqli_connect_errno())
{
echo "Erro ao conectar: " . mysqli_connect_error();
}
if(isset($_POST['submit'])){
$Team=$_POST['Team_Name'];
$Player1=$_POST['Player1'];
$Player2=$_POST['Player2'];
$Player3=$_POST['Player3'];
$Player4=$_POST['Player4'];
$Player5=$_POST['Player5'];
$Age1=$_POST['Age1'];
$Age2=$_POST['Age2'];
$Age3=$_POST['Age3'];
$Age4=$_POST['Age4'];
$Age5=$_POST['Age5'];
$Email=$_POST['Email'];
$register_query = "INSERT INTO `tabela`(`id`, `Team Name 1`, `Team Name 2`, `Team Name 3`, `Team Name 4`, `Team Name 5`, `Age Player 1`, `Age Player 2`, `Age Player 3`, `Age Player 4`, `Age Player 5`, `Team Email`) VALUES ('$Team', '$Player1', '$Player2', '$Player3', '$Player4', '$Player5', '$Age1', '$Age2', '$Age3', '$Age4', '$Age5', '$Email')";
try{
$register_result = mysqli_query($conn, $register_query);
if($register_result){
if(mysqli_affected_rows($conn)>0){
echo("registration successful");
}else{
echo("error in registration");
}
}
}catch(Exception $ex){
echo("error".$ex->getMessage());
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>REgistrar</title>
</head>
<body>
<h1> Cadastrar Utilizador </h1>
<form name="signup" method="POST" action="ultima_tentativa.php">
<label>Team Name</label>
<input type="text" name="Team_Name" placeholder="Team Name"><br><br>
<label>Player 1</label>
<input type="text" name="Player1" placeholder="Player 1"><br><br>
<label>Player 2:</label>
<input type="text" name="Player2" placeholder="Player 2"><br><br>
<label>Player 3:</label>
<input type="text" name="Player3" placeholder="Player 3"><br><br>
<label>Player 4:</label>
<input type="text" name="Player4" placeholder="Player 4"><br><br>
<label>Player 5:</label>
<input type="text" name="Player5" placeholder="Player 5"><br><br>
<label>Age Player 1:</label>
<input type="int" name="Age1" placeholder="Age Player 1"><br><br>
<label>Age Player 2:</label>
<input type="int" name="Age2" placeholder="Age Player 2"><br><br>
<label>Age Player 3:</label>
<input type="int" name="Age3" placeholder="Age Player 3"><br><br>
<label>Age Player 4:</label>
<input type="int" name="Age4" placeholder="Age Player 4"><br><br>
<label>Age Player 5:</label>
<input type="int" name="Age5" placeholder="Age Player 5"><br><br>
<label>Team Email:</label>
<input type="text" name="Email" placeholder="Email Team"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
put a
mysqli_error
after executing the query and see if it returns something.– Pedro Augusto
https://www.w3schools.com/php7/default.asp
– Thalles Rangel
The fields cannot have spaces in INSERT. You put this only for example or this is the real code?
– Lucas Augusto Coelho Lopes