insert in database with php and html

0

I am mediating a nav-item (bootstrap) by saving data in a database using a php file, but at the time of saving the data the php file is opened and I would like it to be executed only without it being opened, that is, that only makes the insertion of data without it being opened.

the nav-item in my file:

        <ul class="nav flex-column">
          <li class="nav-item">
            <a class="nav-link active" href="#">
              <span data-feather="home"></span>
              Dashboard <span class="sr-only">(current)</span>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="y.php?valor=0">
              <span data-feather="file"></span>
              Activar
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">
              <span data-feather="bar-chart-2"></span>
              Reportes
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">
              <span data-feather="layers"></span>
              Operaciones
            </a>
          </li>
        </ul>

My php file:

<?php include ('functions.php');
$valor=$_GET['valor'];

ejecutarSQLCommand("UPDATE fs SET State='$valor' WHERE Color= 'red'");

 ?>
    
asked by Juan Trinidad Mayo 27.01.2018 в 19:14
source

1 answer

1

So that you do not refresh the page, during the insertion of data, you can use the ajax functions provided by jquery
Example:

var ruta="localhost/aplicacion/y.php?valor=0";
$.ajax( 
{ url:  ruta , method:"GET", success:function(data){ alert("agregado!");}
}
);

Create the route according to your case This can be put into a function

<script type="text/javascript">
function insertar(){
var ruta="localhost/aplicacion/y.php?valor=0";
$.ajax( 
{ url:  ruta , method:"GET"}
);
}
</script>

And to call this function, for example

  <li class="nav-item">
            <a class="nav-link" href= "#"  onclick="insertar()">
              <span data-feather="file"></span>
              Activar
            </a>
          </li>
    
answered by 27.01.2018 / 20:06
source