Problem to update record with php and mysql combobox?

0

I'm doing the update of a record in my BD by <select> but it does not work for me.

monitoringService.php

<html>
<head>
  <form method="POST" action="actualizarSeguimiento.php">
    <label>Situacion: </label>
        <select type="selec" name="situacion[]" id="situacion">
            <option value='".$situacion."'>Finalizado</option>
            <option value='".$situacion."'>Fallido</option>
            <option value='".$situacion."'>Cancelado</option>
            <option value='".$situacion."'>Programado</option>
            <option value='".$situacion."'>Realizando</option>
        </select>
   </form>    
</body>
</html>

updateTracking.php

<?php
    $conexion =  mysqli_connect("localhost", "root", "admin123", "database");

    $servicio_No = $_POST["servicio_No"];
    $situacion = $_POST["situacion"];

    mysqli_query($conexion,"UPDATE servicio SET situacion = '$situacion'   WHERE servicio_No = '$servicio_No'") or die("ERROR AL ACTUALIZAR");

   mysqli_close($conexion);
?>
    
asked by Cristian Antonio Trujillo Gris 08.06.2018 в 22:02
source

2 answers

0
  • Your <head> tag is not closed and your </body> tag is unopened.

    <html>
    <head></head>
    <body>
      <form method="POST" action="actualizarSeguimiento.php">
        <!-- Código de tu formulario -->
       </form>    
    </body>
    </html>
    
  • As you define the action of your form, your updateFollowing.php must be in the same folder as trackingService.php . If it is in another folder you should specify it.

  • I would remove the brackets from the attribute name of select - > name="situacion" unless you are looking for a multiple selection.

  • Is the variable $situacion of your <option> where it comes from?
  • Where servicio_No comes from, which you recover by POST in updateTracking.php - > $servicio_No = $_POST["servicio_No"];
  • Why do all the options pass the same variable to the value attribute? I think the idea would be that the value would be different depending on which option they choose.
  • I recommend that to retrieve values with $ _POST use the following function $situacion = mysqli_real_escape_string($conexion, $_POST['situacion']); You can find more information about this function here .
  • If you are not sure if your values are going to update tracking correctly, you can add a echo $situacion to the end of that same file to see what value the variable has and be able to debug errors.
answered by 09.06.2018 / 08:26
source
1

I do not understand what you want to do, but you will need something similar to this, considering that you need to set the variable $servicio_No previously.

monitoringService.php

<html>
    <head></head>
    <body>
        <form method="POST" action="actualizarSeguimiento.php">
            <input type="hidden" name="servicio_No" value="<?php echo $servicio_No ?>" />

            <label>Situacion: </label>
            <select name="situacion" id="situacion" onchange="this.form.submit()">
                <option value="Finalizado">Finalizado</option>
                <option value="Fallido">Fallido</option>
                <option value="Cancelado">Cancelado</option>
                <option value="Programado">Programado</option>
                <option value="Realizando">Realizando</option>
            </select>
       </form>    
    </body>
</html>

You need to set servicio_No , since that is what you get to do the update in your query, also assuming that the field situacion of the table servicio is alphanumeric

updateTracking.php

<?php
    $conexion =  mysqli_connect("localhost", "root", "admin123", "database");

    $servicio_No = $_POST["servicio_No"];
    $situacion = $_POST["situacion"];

    mysqli_query($conexion,"UPDATE servicio SET situacion = '$situacion'   WHERE servicio_No = '$servicio_No'") or die("ERROR AL ACTUALIZAR");

    mysqli_close($conexion);
?>
    
answered by 08.06.2018 в 22:07