How to send SQL data with pre-defined data in PHP

1

Using a while repeat structure, I want to send predefined data. I'll try to show.

Database: Name: (joao, gabriel, vitor) mode: (0,0,0)

pagina1.php

<?php
session_start();
include_once("config.php");
?>

<?php 
$sql = $db->query("SELECT nome,modo FROM banco_de_dados");
?>

<?php
while($dados = $sql->fetch_array()){
    $nome = $dados['nome'];
    $modo = $dados['modo'];

    $_SESSION['nome_id'.$num] = $nome;
    $num++;

?>
<center>
NOME: <?php  
echo $nome;
?> |
<?php  
echo $modo;
?> |
<a href="pagina2.php" role="button">ON//OFF</a><br>
</center>


<?php
}
?>

page2.php

<?php
session_start();
require_once 'pagina1.php';

$sql_up = "UPDATE bando_de_dados SET modo = ('1') WHERE nome = '$nome'" ;
$up = mysqli_query($db, $sql_up);

?>

When you click on on//off , it changes from 0 to 1 . (It will change from 1 to 1, depending on the click)

    
asked by anonymous 29.06.2018 / 03:49

1 answer

0

You should pass the values you want to pass as a parameter to pagina1.php as a parameter in página2.php .

<center>
 NOME: <?php echo $nome; ?> | <?php echo $modo; ?> | <a href="pagina2.php?nome=<?= $nome ?>&modo=<?= $modo ?>" role="button">ON//OFF</a><br> 
</center>

In% w_of% you will read these variables and use them in your SQL as follows.

$nome = $_GET('nome');
$modo = $_GET('modo');

There are other ways you can do this, but that fits your need.

    
29.06.2018 / 20:23