-2

I have a jquery code when I click in an input button launch an event to post updateEstado.php.

Code:

$('input[type="submit"]').click(function(event){
    event.preventDefault(); // disable action of the input buttons

    // Get the value of the input fields
   var inputvalue = $(this).attr("value");

    // Send Ajax request to updateEstado.php, with value set as 'input' in the POST data
    $.post('updateEstado2.php', {estado: 'DESACTIVAT', codigo: '38'});


    alert(inputvalue);          

}); 

PHP:

<?php   
        session_start();

        if(isset($_SESSION['username']) and $_SESSION['username'] <> ''){

                include("db_tools.php"); 

                $conn = dbConnect("localhost", "5432", "dbname", "dbuser", "dbpass");  


                $estado = $_POST['estado'];

                $codigo = $_POST['codigo'];

                echo "<br>Estado: " + $estado;
                echo "<br>Codigo: " + $codigo;

        /*      
                $query = "UPDATE produccion.ma_producto SET estado={$estado} WHERE codigo={$codigo}"; 

                $result = pg_query($conn, $query);  

                if ($result == TRUE) {
                    header('Location: produccio.php');
                } else {
                    echo "Error updating record: " . $conn->error;
                }   */

                $conn->close();

        } else{
            ?><p>La sessió no està activa, si us plau ingresa <a href="login.php">aquí</a></p>
<?php   
        }?>

This code working fine because I show the alert message only when I clic in a button doesn't launch to post updateEstado.php in the debug console of the browser show this error message:

enter image description here

I have tried a php page with only echo "test"; but it doesn't work too, it show the same error message.

Please Could you help me?

ruzD
  • 555
  • 1
  • 15
  • 29

1 Answers1

1

In your php use

echo "<br>Estado: " . $estado;
echo "<br>Codigo: " . $codigo;

Not

echo "<br>Estado: " + $estado;
echo "<br>Codigo: " + $codigo;

And $_SESSION['username'] != ''

G. Mansour
  • 696
  • 6
  • 15