Change input type="radio" by input type="image" + php

0

good day, I currently use the input type radio with the post method to get information:

<td class="borrar">
                    <form method="post" action="location.reload()" name="eliminado">
                    <input  type="radio" name="eliminado" onclick="document.forms.prueba.submit()" value="<?php echo $data['cedula']?>"> </td>

and I get it in php like this:

 if(isset($_POST['eliminado'])) 

        { $del = $_POST['eliminado'];

        }  else {$del = '';
            }


    if($del != "" ) 

      {$deleting = "Update resultados set borrado='".$del."' WHERE cedula = '".$del."';";

        $deleting2=mysqli_query($con,$deleting) or die ("Location: ../error.php");

            }  else {};

However I would like not to use the "radio" but the image of a trash can, however when I make this change it does not complete the action to erase.

<td class="borrar">
       <form method="post" action="location.reload()" name="eliminado">
       <input  type="image"  src="../imagen/papelera.png" name="eliminado" onclick="document.forms.prueba.submit()" value="<?php echo $data['cedula']?>"> </td>
    
asked by Carlos Pulgarin 02.10.2018 в 02:40
source

1 answer

0

For what I understood you want, when you click on an image, a record is deleted from the database. To solve your problem I would try putting a hidden input. I would do it like this:

<td class="borrar">
  <form method="post" action="location.reload()" name="eliminado">
   <input type="hidden" value="<?php echo $data['cedula']; ?>" name="cedula">
   <input  type="image"  src="../imagen/papelera.png" onclick="document.forms.prueba.submit()"> 
  </form>
</td>

And in Php:

    $sql = "UPDATE resultados SET borrado=eliminado WHERE cedula = "'.$_POST['cedula'].'"";

    $query = mysqli_query($con,$deleting) or die ("Location: ../error.php");
  
  • You have to close the form tag.
  •   
  • Inputs are not recommended: image have a value.
  •   
  • In this case you do not need the isset in php, the hidden field should always be sent, although if you want to do it right, it's fine.
  •   
    
answered by 02.10.2018 / 09:34
source