Send variable PHP to table in MySQL

0

I would like to send these php variables with a INSERT INTO that I print in html tables, but I do not know how to do it or if you can

Here is an example of one of the tables I have

    <!-- Jornada 1 -->
  <p><b>Jornada:</b> 1</p>
  <p><b>Fecha de encuentro:</b> <?php echo $start ?></p>

<table class="table">
  <thead align="center" class="thead-dark">
    <tr>
      <th scope="col">Local</th>
      <th scope="col">Visitante</th>
    </tr>
  </thead>
  <tbody align="center">
    <tr>
      <td scope="row" value="<?php echo $eq7;?>"><?php echo $name7 ?></td>
      <td value="<?php echo $eq8;?>"><?php echo $name8 ?></td>
    </tr>
    <tr>
      <td scope="row" value="<?php echo $eq9;?>"><?php echo $name9 ?></td>
      <td value="<?php echo $eq4;?>"><?php echo $name4 ?></td>
    </tr>
    <tr>
      <td value="<?php echo $eq5;?>"><?php echo $name5 ?></td>
      <td value="<?php echo $eq2;?>"><?php echo $name2 ?></td>
    </tr>
    <tr>
      <td scope="row" value="<?php echo $eq1;?>"><?php echo $name1 ?></td>
      <td value="<?php echo $eq6;?>"><?php echo $name6 ?></td>
    </tr>
    <tr>
      <td scope="row" value="<?php echo $eq3;?>"><?php echo $name3 ?></td>
      <td value="<?php echo $eq10;?>"><?php echo $name10 ?></td>
    </tr>
  </tbody>
</table>
<!-- Fin jornada 1 -->

The variables that I have to send are ids, like for example the $eq7 (Even if I do not know if this can be done)

Could you help me?

Thanks

    
asked by 11.04.2018 в 11:34
source

1 answer

2

You do not understand very well what you need, but I think you mean to create a connection to the database to save the values of $ eqX in a table, but you do not tell us what your database is like or anything, that my example will not be worth it as such and you will have to adapt it to your needs. But basically it's about connecting to the database and making the insert:

<?php
    $mysqli = new mysqli("localhost", "usuario_base_de_datos", "contraseña_base_de_datos", "nombre_base_de_datos");
    if($mysqli->connect_errno) {
        printf("Falló la conexión: %s\n", $mysqli->connect_error);
        exit();
    }
    $mysqli->query(sprintf("INSERT INTO tabla (%d, %d)", $eq1, $eq2));
?>

This will insert into the database the values $ eq1 and $ eq2 in a table called table that is presumed to have the fields eq1 and eq2. Logically, you have to create the table with the additional fields you want and modify the INSERT line to add the fields.

Also say that it can be done like this (insecure) or using PDO (more secure) and in any case, you should check this link that talks about SQL Injection: How to avoid SQL injection in PHP?

    
answered by 11.04.2018 / 12:09
source