Problems entering data into database

Asked

Viewed 68 times

0

Good, I’m here with a problem because I enter all the data but does not keep me in the database. Does anyone here know the problem with the following codes:

<form action="php/RegistoFederados.php" id="formF" method="post">
<table cellspacing="0" cellpadding="0">
<tr>
<td>Sexo</td>
<td><select name="sexo" id="sexo" required>
	<option value="">Escolha uma opção</option>
	<option value="M">Masculino</option>
	<option value="F">Feminino</option>
</select></td>
</tr>
<tr>
<td>Nome Completo</td>
<td><input type="text" class="txtfield" name="nome" placeholder="Nome Completo" required ></td>
</tr>
<tr>
<td>Data de Nascimento</td>
<td><input type="date"  name="dataNasc"  required></td>
</tr>
<tr>
<td>BI ou CC</td>
<td><input type="text" class="txtfield" name="bi" maxlength="8" placeholder="BI ou CC" required onblur="Vbi()"></td>
</tr>
<tr>
<td>Nº licença de Federado</td>
<td><input type="text" class="txtfield" name="Nfederado" id="nf" onblur="Vfed()" required></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" class="email" name="email" placeholder="[email protected]" required></td>
</tr>
<tr>
<td>Telemovel</td>
<td><input type="text"  id="tlm" class="txtfield" name="telemovel" maxlength="9" required onblur="Vtlm()"></td>
</tr>
<tr>
<td>Morada</td>
<td><input type="text" class="txtfield" name="morada" required></td>
</tr>
<tr>
<td>Levantamento de dorsais</td>
<td><select name="localdorsal" id="localS" required>
	<option value="">Escolha uma opção</option>
	<option value="loja">Loja Jomara</option>
	<option value="PUA"> Quiosque do Conhecimento PUA</option>
</select></td>
</tr>
<tr>
<td>Metodo de Pagamento **</td>
<td><Select name="pagamento" required>
	<option value="">Escolha uma opção</option>
	<option value="Dinheiro">Dinheiro</option>
	<option value="Transferência">Transferência Bancaria</option>
</select></td>
</tr>			
<tr>
<td>Equipa</td>
<td><input type="text" class="txtfield" name="equipa"></td>
</tr>
<tr>
<td>Prova</td>
<td><select name="prova" required>
	<option value="">Escolha uma opção</option>
	<option value="45 km">Meia-Maratona 45 KM</option>
	<option value="70 km">Maratona 70 KM</option>
</select></td>
</tr>
<tr>
<td>Almoço</td>
<td><select name="almoco" required>
	<option value="">Escolha uma opção</option>
	<option value="1">Sim</option>
	<option value="0">Não</option>
</select></td>
</tr>
<tr>
<td colspan="2"><input type="submit" class="Sinscricao" value="Submeter Inscrição"></td>
</tr>
</table>
<p>**Nas inscrições se o pagamento for por transferência bancária, deverá ser enviado o comprovativo por e-mail com o nome completo do atleta</p>
</form>

<?php
	$con = mysqli_connect("localhost","root","","jomara");
	
	$sexo = mysql_real_escape_string($_POST['sexo']);
    $nome = mysql_real_escape_string($_POST['nome']);
	$dataNasc = mysql_real_escape_string($_POST['dataNasc']);
    $bi = mysql_real_escape_string($_POST['bi']);
	$nf = mysql_real_escape_string($_POST['Nfederado']);
    $email = mysql_real_escape_string($_POST['email']);
    $telemovel = mysql_real_escape_string($_POST['telemovel']);
    $morada = mysql_real_escape_string($_POST['morada']);
    $local_dorsal = mysql_real_escape_string($_POST['localdorsal']);
    $pagamento = mysql_real_escape_string($_POST['pagamento']);
    $equipa = mysql_real_escape_string($_POST['equipa']);
    $categoria = mysql_real_escape_string($_POST['categoria']);
    $almoco = mysql_real_escape_string($_POST['almoco']);
    $pago = 0;
	
	$sql = "INSERT INTO registofederados(sexo,nome,dataNasc,bi,numero_federado,email,telemovel,morada,local_dorsal,pagamento,equipa,categoria,almoco,pago) VALUES('$sexo','$nome','$dataNasc','$bi','$nf','$email', '$telemovel', '$morada', '$local_dorsal', '$pagamento', '$equipa', '$categoria', $almoco, $pago)";
	
	if(mysqli_query($con, $sql)){
	echo "<script>
             alert('Inscrição realizada'); 
             window.history.go(-2);
     </script>";
	}
	else{
		echo "<script>
             alert('Inscrição não realizada'); 
     </script>";
	 header('Location: ../federados.html');
	 }
?>

  • 2

    Your table is really "registofederados" was not to be registered?

  • places inside the else the following code echo mysqli_connect_error(); and comments on the //header('Location: ../federados.html');, then put here the result.

  • this helped a lot, thanks, the problem was in $category = mysql_real_escape_string($_POST['category']); that was supposed to be $category = mysql_real_escape_string($_POST['proof']); but now that tested, appears the page appears blank

  • @Kayobruno yes the table is even called "registofederados"

  • Thank you for your support but I already solved the problem (my stupidity) I had forgotten to insert a field in the table

1 answer

0


First always check if the database data matches the php data. Then always check that the data in php is the same as the form in the html page. That was my problem and I’m answering my question so there’s no one else going through the stupidity that I went through.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.