i have a page wich shows CV´s from a option select list wich retrieves the rows name and srname from the CV's table on the database, and when the post_form button is clicked it gets the id from the current selected name on the option list and shows all the rows where the id is equal to the one of the name on the select list.
SO NOW i've created a form with 2 buttons wich appears with the CV whenever it is posted with an action to call a external php file to do some Mysql operations, wich are to send the current displayed table rows to the reproved_candidates table or to the aproved_candidates table and after both operations adding a delete operation to delete it from the current table wether it is reproved or aproved.
i managed to pass the id from the selected name on the list to the external php page but something's wrong i cant figure out why the operations are failing.
post_form $con:
<?php if (isset($_POST["post_form"])) {
$selectedUser = intval($_POST['users']); //pra selecionar o nome clicado na option list
if($selectedUser > 0){
$con = mysqli_connect("localhost","root","","chevron");
$q = "SELECT * FROM candidatos WHERE id = ".$selectedUser." ";
$result = mysqli_query($con, $q);
if (!$result) {
echo "ERROR";
}
$row = mysqli_fetch_array($result);
if(is_array($row) && count($row) > 0){
echo "<center><strong>CANDIDATO Nº.:</strong>".$selectedUser." <br><br><br></center>";
echo "<strong>NOME:</strong><br>".$row["nome"]."<br><br><br>";
echo "<strong>SOBRENOME:</strong><br> ".$row["sobrenome"]."<br><br><br>";
echo "<strong>MORADA:</strong><br> ".$row["morada"]."<br><br><br>";
echo "<strong>BI:</strong><br> ".$row["bi"]."<br><br><br>";
echo "<strong>EMAIL:</strong><br> ".$row["email"]."<br><br><br>";
echo "<strong>COMPETENCIAS:</strong><br> ".$row["competencias"]."<br><br><br>";
echo "<strong>IDIOMAS: </strong><br>".$row["idiomas"]."<br><br><br>";
echo "<strong>OBJECTIVO:</strong><br> ".$row["objectivo"]."<br>";
echo " <center>
<form class='decisions' method='POST' action='edit-record.php?id=".$row['id']."'>
<p>
Se achar esta candidatura excepcional e quiser mostra-la ao ADMINISTRADOR marque a caixinha pequena que esta apos o botão qualificado!
</p>
<input type='submit' name='btn_negar' value='NÃO QUALIFICADO'>
<input type='submit' name='btn_aceitar' value='QUALIFICADO'>
<input type='checkbox' name='checkbox_recomend' value='Recomendar ao Administrador'>
</form>
</center>";
}
}
}
?>
edit-record.php (EXTERNAL PHP FILE)*NOT WORKING:
<!-- PHP TIME -->
<!-- botao negar -->
<?php if (isset($_POST['btn_negar'])) {
$selectedUser1 = $_GET['id'];
echo "<script>alert('Concorrente Eliminado')</script>";
echo $_GET['id'];
}
?>
<!-- botao aceitar -->
<?php if (isset($_POST['btn_aceitar'])) {
$selectedUser1 = $_GET['id'];
$con = mysqli_connect("localhost","root","","chevron");
$insere2 = "INSERT INTO candidatos_aptos FROM candidatos WHERE id = ".$_GET['id']."";
$apagar2 = "DELETE * FROM candidatos WHERE id = ". $_GET['id']."";
$result = mysqli_query ($con, $insere2) or die ("Não foi possível executar a inserção.");
$result = mysqli_query ($con, $apagar2) or die ("Não foi possível executar a exclusão.");
if (!$result) {
echo "<script>alert('Falhou com Sucesso!')";
}
echo "<script>alert('Foi Registrado com Sucesso!')";
}
?>
<!-- checkbox_recomend -->
<?php if (isset($_POST['btn_aceitar']) && isset($_POST['checkbox_recomend'])) {
$selectedUser1 = $row['id'] ;
$conexao = mysqli_connect("localhost", "root","", "chevron");
mysqli_select_db("chevron", $conexão);
$insere3 = "UPDATE candidatos_aptos SET (nome, sobrenome, morada, contacto, bi, email, competencias, idiomas, objectivo, estado) VALUES (nome, sobrenome, morada, contacto, bi, email, competencias, idiomas, objectivo, estado) FROM candidatos WHERE id = ".$selectedUser."";
$apagar3 = "DELETE FROM candidatos VALUES (nome, sobrenome, morada, contacto, bi, email, competencias, idiomas, objectivo, estado) WHERE id = ".$selectedUser."";
mysqli_query ($insere, $conexao) or die ("Não foi possível executar a inserção.");
mysqli_query ($apagar, $conexao) or die ("Não foi possível executar a inserção2.");
echo "<script>alert('Foi Registrado com Sucesso!')";
mysqli_close ($conexao);
}
?>
<!-- PHP TIME -->
The problem might be in the Sql INSERT INTO SELECT
query, that should be
$insere2 = "INSERT INTO candidatos_aptos SELECT * FROM candidatos WHERE id = ".$_GET['id']."";
As explained here on W3Schools
This should work if both tables have same columns. Try it on a shell to be sure it works.