Reload while while giving Submit

Asked

Viewed 107 times

2

I have the need to when load all the content defined in the database query to each while and fill in the fields and give Submit, it record in the database and reload only that loop bringing me the filled database data again. So when I’m posting information and recording in the bank, it updates me which ones are filled and in the future when I load the page the other day I’ll know which ones are filled too.

Code example:

    while (odbc_fetch_row($result)) {

    $sqlConfirma = "SELECT inf_km, km FROM dba.km
    WHERE dba.km.id= ".$id."";

    echo "<tr>";
        echo "<form name='InsertBanco' action='executar.php' target='_blank' method='post'>
        <td><input type='text' name='km_op' value='".odbc_result($sqlConfirma, "inf_km")."'></td>
        <td><input type='text' name='km' value='".odbc_result($sqlConfirma, "km")."'></td>
        <td><input type='submit' name='InsertBanco' value='Inserir'></td>
        </form>         
        }
echo "</tr>"

This is only one example of the code, it is not itself, since I use many other fields. The solution could be Javascript and Jquery as well.

  • 1

    Explain the need for better interaction, because, in addition to having problems with large data, the question was very comprehensive.

1 answer

2


You could put a confirmation in the field without using that code but with a condition, that it showed only when the Submit had been clicked:

if($_POST['submit']) {
    $sqlConfirma = "SELECT * FROM dba.km WHERE dba.km.id = $id";
    mysqli_query((coneccao), $sqlConfirma;

    echo 'Adicionado com sucesso á base de dados: ' . $inf_km . ', ' . $km . '.';

}

But if you prefer this way you can do it by entering this code in value or even in the placeholder to not have q delete to enter a new one.

Another way would be at the end of the data being saved, generate a GET link to another page (or to the same one) with the entered data. If you choose to do this just create a header at the end of php like this:

header(Location:'(nome_do_ficheiro)?inf_km=' . '$(inf_km)' . '&amp;km=' . $(km) . '&amp;id=' . $id');

I put in parenthesis q did not know already that they are variable and files you would have to create.

I hope I helped, MDC

  • Brother I’ll have to change some things there, but helped too, you gave me a path that I believe will work. I give the Ubmit to the same page he already recharges and confirms me, but how and much information he will have to sweep the entire bank again, so that’s why he wanted to reload the loop. the more you gave me a cool alternative. Thank you.

  • Ah, a question who knows can help me. How do I do within a value reading in php put a comparison condition? I’ve tried: echo "<inpu.... value=' ".if(condição){}." ' "; More not right. I didn’t want to change everything in html again. value=" <?php echo if() ?>"

  • @Williancoqueiro Make this condition earlier in a variable or ternary. It would be easier. As for your doubt, if it worked out, then mark it as the right answer.

  • Or you can put echo into the condition: if(...){ echo '...'} Else{echo'...'}

Browser other questions tagged

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