0

I need to know how to manage a PHP page in which once you push a confirm button inside the database in MySQL connected to the PHP file the tuple of a table (x) is sending to a table (y) and then they are deleted from the table (x).

This is my code:

Primo file ricerca.php

  <tr>
    <td> <?php echo $row['Nome_richiedente']; ?></td>
    <td> <?php echo $row['Cognome_richiedente']; ?></td>
    <td> <?php echo $row['Indirizzo_richiedente']; ?></td>
    <td> <?php echo $row['Città_richiedente']; ?></td>
    <td> <?php echo $row['Tipo_richiesta']; ?></td>
    <td> <?php echo $row['email_cliente']; ?></td>
    <td> <?php echo $row['Descrizione_richiesta']; ?></td>

    <form method="post" >
        <input type="submit" name="button1" value="Button1"/> 
  </tr>
                        
<?php

    if(array_key_exists('button1',$_POST)){
        include "prova.php";
        funziona();
    }

  }
}
?>
  </table>
 </body>
</html>

Secondo file prova.php

 <?php
    function funziona() {
        $connessione= mysqli_connect("localhost","root","","db_tech");
        $query_insert = "INSERT INTO richista_c SELECT * FROM richiesta;";
         echo "Function Exists";
    }
 ?>
Arkar Aung
  • 3,554
  • 1
  • 16
  • 25
  • 1
    you need to execute the query, also note mysqli_connect is blocking. if for some reason it fails or hangs your dom will be half rendered – Lawrence Cherone Jun 25 '20 at 17:20

1 Answers1

-1

you can use this code for coping all datas from a table to another

$sql    = "INSERT INTO 'table_name' SELECT *  FROM other_table";

and using below code to copy specific comulns:

$sql    = "INSERT INTO 'table_name' (column1 , column2, column3 , ...) SELECT column1_other_table , column2_other_table, column3_other_table , ... FROM other_table";

and your function should be something like this:

function fonziona() {
 
        $connection = new mysqli("localhost","root","","db_tech");
 
        if ($connection -> connect_error){
            echo "Failed to connect to db: " . $connection -> connect_error;
        }
        $connection -> query("SET NAMES utf8");
 
        return $connection;


}

then use query

$connection = fonziona();
$connection -> query($sql);
TheFaultInOurStars
  • 3,464
  • 1
  • 8
  • 29
  • Like this? ------------------------------------------------------- connect_error){ echo "Failed to connect to db: " . $connection -> connect_error; } $connection = fonziona(); $connection -> query($sql); return $connection; } ?> ------------------------------------------------------- sorry i cant ctrl+k in the comments – SirKaze Jun 25 '20 at 17:55
  • you do not need to return it, , also don't use `fonziona` function in itself, just use the code i wrote – TheFaultInOurStars Jun 25 '20 at 18:02
  • You need to stop manually checking for errors. Please read: [Should we ever check for mysqli_connect() errors manually?](https://stackoverflow.com/q/58808332/1839439) and [Should I manually check for errors when calling “mysqli_stmt_prepare”?](https://stackoverflow.com/q/62216426/1839439) – Dharman Jun 25 '20 at 20:07