0

Mi código de actualización no funciona. Estoy trabajando con ajax, php, html y postgres. Estoy trabajando con ajax porque tengo un combo donde la respuesta se almacena en ($r) y la tabla que se muestra se basa en esa selección previa.

Cuando hago clic en Confirmar, se puede ver que carga pero no se aplica la ACTUALIZACIÓN.

conection.php

?php
  ob_start();
  $error = "";
  $host = "localhost";
  $db = "xxxx";
  $tbanimal ="animales";
  $tbzone ="zone";
  $user = "postgres";
  $pw = "admin";
  $port = "5432";
  $packedString = "host=" . $host . " dbname=" . $db . " user=" . $user . " password=" . $pw . " port=" . $port;
  $conn =  pg_connect($packedString)or die('Could not connect: ' . pg_last_error());
?>

Mi código:

tableSupport.php

<?php
include_once "../conection.php";
session_start();

$r = intval($_GET['r']);


    $query="select row_number() OVER (order by z.cv_zone, a.id_animal, a.description) as No,
    e.id_animal, a.description, z.cv_zone from $tbanimal a , $tbzone z 
        where a.id_animal in ($r) and a.cv_zone = z.cv_zone 
        and a.status = 1
    group by z.cv_zone, a.id_animal, a.description
    order by by z.cv_zone, a.id_animal, a.description";


    $result = pg_query($query) or die('Query failed: ' . pg_last_error());
    $rows = pg_num_rows ($result);
    $i = pg_num_fields($result);

    echo "<table class='table table-striped'  border=1> <thead><tr> ";
    for($j=0; $j<$i; $j++){
            $fieldname=pg_field_name($result, $j);
            echo "<th>".strtoupper($fieldname)."</th>"; //columns
            if($j== $i-1){
                                    echo "<th>NOT SUPPORT</th>"; //columns
                                    $j++;
                        }
    }
    echo "</tr> </thead>"
    ?>
    <?php 
        echo "<tbody>";
        while ($line = pg_fetch_array($result)){
            echo "<tr class='table-fixed'>"; 
            for($j=0; $j<$i; $j++){
                    if ($line[$j] <> "") {
                            echo "<td>$line[$j]</td>";
                            if($j== $i-1){
                                $notSupport = $line['id_animal'];
                                echo "<td> <input name='notSupport[]' type='checkbox'  id='notSupport[]' value='$notSupport' class='cbox2'> Not Support</td>";
                                    $j++;
                            }
                    }
                    else{
                            echo"<td>&nbsp;</td>";  
                    }
            }   
            echo "</tr>";   
        } 
        echo "</tbody>";
        echo "</table>";
    ?>
    <script>
    $(function() {
    $('.cbox2').click(function()  {
                                count=$('.cbox2:checked').length;
                                text = 'Not supported: ' + count;
                                $('#small2').html(text);
                                if(count < 1)
                                    $(':input[type='update']').prop('disabled', true);
                                else
                                {
                                    $(':input[type='update']').prop('disabled', false);
                                }
    });
});
</script>   

deleteSupported.php

<?php
include_once "includes/conection.php";
if(isset($_POST['update']))
            {    
                $dbconn = pg_connect($packedString)or die('Could not connect: ' . pg_last_error());

                try{

                    $id_animal = implode("','", $_POST['id_animal']);
                }
                catch (Exception $e) {
                    echo "You did not select any supported. Redirecting ...";
                }

                for($x=0; $x < count($id_animal); $x++)
                {

                    $query="UPDATE $tbanimal SET status = 0 WHERE id_animal in ({$id_animal})";
                    pg_query($query) or die('Insert failed: ' . pg_last_error());
                }
                echo "<script> alert('You have canceled $x supports. Redirecting ...'); </script>";
                echo "<meta http-equiv='refresh' content='0'>";         
            }
?>

Mi botón

<form type="update" method="post" role="form-horizontal" id="form-fil">
     <button onclick="ns.confirmar=0" type="submit" name="update" class="btn btn-danger" value="cancelar" disabled>
                        <span class="fas fa-minus-circle">
                        </span> Confirm
    </button>
</form>
4
  • A la query le estas pasando tu conexión a la bd? Commented el 13 abr. 2018 a las 5:29
  • si claro, anexaré mi código de conexión conection.php a mi post Commented el 13 abr. 2018 a las 14:50
  • y cuando tu haces: $result = pg_query($query) donde mandas a llamar a la conexión? Commented el 13 abr. 2018 a las 18:19
  • Desde include, de hecho mi tabla si se esta costruyendo, lo que no funciona es el input, no esta entrando a mi codigo deleteSupported.php Commented el 13 abr. 2018 a las 18:43

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.