I need to take the patient id from the table to the next page, along with the user, by clicking the button

Asked

Viewed 47 times

0

<?php
$conexao = new mysqli("localhost","root","","hospital");

if($conexao->connect_errno){
    echo"Failed to connect to MySQL: (" . $conexao->connect_errno   .") " . $conexao->connect_error;
}

$res = $conexao->query("SELECT nome, idade, cpf from paciente, ficha_atendimento, questionario WHERE paciente.id = ficha_atendimento.id_paciente AND paciente.id = questionario.id_paciente");


echo "<table class='table table-striped'>";
echo "<tr>
        <td>Nome</td>
        <td>Idade</td>
        <td>CPF</td>
        </tr>";

while($row = mysqli_fetch_assoc($res)) {

    echo "<tr class='info'>
    <td>". $row['nome']."</td>
    <td>". $row['idade']."</td>
    <td>". $row['cpf']."</td>
    <td><a href='sala_questionario.php'><button class='btn btn-info'>Redirecionar</button></a></td>
    </tr>";
}

echo "</table>";


?>

The 'patient' table has the name age and Cpf fields, and all of these are being printed in the table, next to a button (in the code above) that redirects the patient to a page that he will answer a questionnaire. However, I need to take this patient’s id to this next page when it’s redirected, so that when he answers the questionnaire the program sends the data to the 'questionnaire' table that has a foreign key called id_patient that corresponds to the patient id of the 'patient' table. (that is, the problem is that all are being redirected to the same page, without differentiating who is answering the questionnaire).

1 answer

0


You can do this using the method ?_GET, would look this way:

<td><a href='sala_questionario.php?id=$row['id']'><button class='btn btn-info'>Redirecionar</button></a></td>

And on the page sala_questionario, for you to take the value, would be like this:

$id = $_GET["id"];
  • Parse error: syntax error, Unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting Identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C: xampp htdocs TCC mostrar_questionario.php on line 24 - this error appears

  • And which would be line 24?

  • <td><a href='sala_questionario.php? id=$Row['id']'><button class='btn btn-info'>Redirect</button></a></td>

  • Try to set the id variable before you run it through get. $id = $row ['id']; and <td><a href='sala_questionario.php?id=$id'><button class='btn btn-info'>Redirecionar</button></a></td>

  • So brother, I tried it in several ways and it worked that last one you sent when I change the 'id' for Cpf, which also serves because I can get the id later through Cpf, since nobody will have the same Cpf. However, he is printing the sala_questionnaire page on the page that the button is on and not changing the page. If we can’t solve this, we give an Hide() in the table with the buttons and it’s over. The problem that remains even is that the get that you pasosu me is not working. This appears: Notice: Undefined index: Cpf in C: xampp htdocs TCC sala_questionario.php on line 10. Line 10 ta o get

  • Update your question with the new php, so I can help you.

  • Man, I didn’t see you changing the page. Ta working well bro, now just give Hide in table q for some reason it goes together to another page hahah. But this then I do good, Fight man, helped a lot !! Sorry anything <3

  • Don’t forget to mark the answer as correct.

Show 3 more comments

Browser other questions tagged

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