How to send SQL data with pre-defined PHP data

Asked

Viewed 43 times

1

Using a repeating structure while I want to send predefined data. I’ll try to show.

Database: name:(John,Paul,Victor) mode:(0,0,0)

page1.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);

?>

IMAGEM - EXEMPLO

By clicking on on//off, mute 0 for 1.(Will change from 1 by 1, according to the click)

  • As well as predicted data?

  • It seems to me that he wants to know how to send a parameter to pagina2.php

  • example: name:(Joao,Gabriel,Vitor) mode:(0,0,0)

1 answer

0

You must pass as parameter in pagina1.php the values you want to pass as parameter to 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 the página2.php you will read these variables and use them in your SQL as follows.

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

There are other ways to do it, but it meets your need.

Browser other questions tagged

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