Do not insert in table

Asked

Viewed 50 times

0

I have this code:

<?php  
$servername = "xxx.xxx.x.xx";
$username = "xxxxx";
$password = "xxxxxxx";
$dbname = "xxxxxxx";

$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset('utf8');

$data = $_POST['DataEntrada'];  
$utente = $_POST['Utente'];
$observacao = $_POST['Observacao'];
$estado = $_POST['Estado'];
$colaborador = $_POST['Colaborador']

$sql = "INSERT INTO regOratorio (`DataEntrada`,`Utente`,`Observacao`,'Colaborador') 
VALUES ('$data','$utente','$observacao','$colaborador')";

if ($conn->query($sql) === TRUE) {
$last_id = $conn->insert_id;
} 

$sql1 = "INSERT INTO EstadoOratorio (`IdOrat`,`Estado`) 
VALUES ('$last_id','$estado')"; 

 if ($conn->query($sql1) === TRUE);

$rowCount = $query->num_rows;

$conn->close();
 ?> 

<form name="customer_details" method="POST" onsubmit="return form_validation()" >
<h1><center><strong>Listagem Para Orientação da Participação Para o Oratório</strong></center></h1></br>
</br> 
 
 <fieldset>
 <table cellspacing="10">
 <tr>
   <td>
 <p><h5><strong>Data Oratório</strong></h5> <input type="date" required="" id="DataEntrada" name="DataEntrada" value="<?php echo date("Y-m-d");?>" /><br/></p>
	</td>
</tr>
 </table>
</fieldset>
 
 <fieldset>
 <table cellspacing="10">
 <tr>
   <td>
<label for=""><h5><strong>Utente</strong></h5></label>
    <select id="Utente" name="Utente">
      <option value="1">Carminda Alves</option> 
	  </select> <input type="radio" name="Estado" value="Presente" required>Presente &nbsp;&nbsp;&nbsp; <input type="radio" name="Estado" value="Ausente" required>Ausente <input type="text" id="observacao" name="observacao" size="40" > 
	  </td>
	  </tr>
 </table>
</fieldset>



<fieldset>
 <table cellspacing="10">
 <tr>
   <td>
<label for=""><h5><strong>Responsável de Turno</strong></h5></label>
<select name="Colaborador">
       <option value="0">Selecione Colaborador</option>
        <?php
         $servername = "xxx.xxx.x.xx";
$username = "xxxxx";
$password = "xxxxxx";
$dbname = "xxxxxxxx";

$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset('utf8'); 
        
         $sql = "SELECT * FROM centrodb.InfoLuvas WHERE Funcao = 'AAD' ORDER BY Funcionario ASC";
         $qr = mysqli_query($conn, $sql);
         while($ln = mysqli_fetch_assoc($qr)){
            echo '<option value="'.$ln['Id'].'">'.$ln['Funcionario'].'</option>';
         }
      ?>        
    </select>
</td>
</tr>
 </table>
</fieldset>
<input type="submit" value="Registar"/>
</form>

But when I fill in the form do not enter the data in the tables.

  • What error appears?

  • No error appears on the page, everything works fine, but then I will check the two tables and are empty

  • 1

    One way I learned to solve PHP errors: make a echo in everything to see if the variables are coming and are correct, including the $sql, if everything is ok the problem is in sql, then test it directly in phpmyadmin, you will find the error in any of these processes

  • Thanks, I got it

1 answer

0

Yours is without action.

Ex:

<form name="customer_details" action="minhapagina.php" method="POST" onsubmit="return form_validation()" >
<h1><center><strong>Listagem Para Orientação da Participação Para o Oratório</strong></center></h1></br>
</br> 

 <fieldset>
 <table cellspacing="10">
 <tr>
   <td>
 <p><h5><strong>Data Oratório</strong></h5> <input type="date" required="" id="DataEntrada" name="DataEntrada" value="<?php echo date("Y-m-d");?>" /><br/></p>
    </td>
</tr>
 </table>
</fieldset>

 <fieldset>
 <table cellspacing="10">
 <tr>
   <td>
<label for=""><h5><strong>Utente</strong></h5></label>
    <select id="Utente" name="Utente">
      <option value="1">Carminda Alves</option> 
      </select> <input type="radio" name="Estado" value="Presente" required>Presente &nbsp;&nbsp;&nbsp; <input type="radio" name="Estado" value="Ausente" required>Ausente <input type="text" id="observacao" name="observacao" size="40" > 
      </td>
      </tr>
 </table>
</fieldset>



<fieldset>
 <table cellspacing="10">
 <tr>
   <td>
<label for=""><h5><strong>Responsável de Turno</strong></h5></label>
<select name="Colaborador">
       <option value="0">Selecione Colaborador</option>
        <?php
         $servername = "xxx.xxx.x.xx";
$username = "xxxxx";
$password = "xxxxxx";
$dbname = "xxxxxxxx";

$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset('utf8'); 

         $sql = "SELECT * FROM centrodb.InfoLuvas WHERE Funcao = 'AAD' ORDER BY Funcionario ASC";
         $qr = mysqli_query($conn, $sql);
         while($ln = mysqli_fetch_assoc($qr)){
            echo '<option value="'.$ln['Id'].'">'.$ln['Funcionario'].'</option>';
         }
      ?>        
    </select>
</td>
</tr>
 </table>
</fieldset>
<input type="submit" value="Registar"/>
</form>
  • But I do everything on the same page, I think it doesn’t need action since we don’t call any page to insert in the table

Browser other questions tagged

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