0

I have the following form and this script to connect with the class operation.php it doesn't refresh and neither add the data into database.

I have no idea why it's not adding to the database

Form

<form id="formulario" method="POST">
    <textarea id="valor" name="valor"></textarea>
    <input type="hidden" id="idproyecto" name="idproyecto" value="<?php echo $hist->idproyecto;?>"/>
    <input type="hidden" id="idsprint" name="idsprint" value="<?php echo $hist->idsprint;?>"/>
    <input type="hidden" id="idhistoria" name="idhistoria" value="<?php echo $hist->idhistoria;?>"/>
    <input type="hidden" id="idusuario" name="idusuario" value="<?php echo $user->idusuario;?>"/>
    <input  id="Confirmar"  class="button" name="operacion" type="submit" value="Confirmar" />
    <span class="advertencia" style="display:none"> Please Enter Valid Data</span>
    <span class="completado" style="display:none"> Registration Successfully</span>
</form>

Script

$(function() {
    $(".button").click(function() {
        var idproyecto = $("#idproyecto").val();
        var idsprint = $("#idsprint").val();
        var idhistoria = $("#idhistoria").val();
        var idusuario = $("#idusuario").val();
        var valor = $("#valor").val();
        var dataString = 'idproyecto='+ idproyecto + '&idsprint=' + idsprint + '&idhistoria=' + idhistoria + '&idusuario=' + idusuario + '&valor=' + valor;
         alert(dataString);
        if(valor=='')
        {
            $('.completado').fadeOut(200).hide();
            $('.advertencia').fadeOut(200).show();
        }else{
            $.ajax({
            type: "POST",
            url: "../admin/poker/operacion_poker.php",
            data: dataString,
            success: function(){
                $('.completado').fadeIn(200).show();
                $('.advertencia').fadeOut(200).hide();}
            });
        }
        return false;
    });
});

And i have this class operation_poker.php to receive the values and add to database

PHP

include_once('../../clases/poker.php');
$operacion=$_REQUEST['operacion'];
$temporal_poker=new poker(0,$_REQUEST['idproyecto'],$_REQUEST['idsprint'],$_REQUEST['idhistoria'],$_REQUEST['idusuario'],$_REQUEST['valor'],0);
switch($operacion)
{
    case 'Confirmar':
        $temporal_poker->inserta_poker();
        break;
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Samuel
  • 7
  • 1

2 Answers2

1

You are sending the data via $_POST, try accessing the values from $_POST instead of $_REQUEST. Normally $_REQUEST would have the data in $_POST, but since you are getting information at runtime, PHP may not be updating the $_REQUEST variable.

Here is a great post about variables_order and the best uses for $_REQUEST over $_GET, $_POST and $_COOKIE.

Community
  • 1
  • 1
Matthew R.
  • 4,332
  • 1
  • 24
  • 39
0

Instead of using:

$(function() {
    $(".button").click(function() {, 

use this:

$(function() {
    $("#formulario").submit(function(event) {
      event.preventDefault();

Since your button is a submit type, you have to intercept form's submit event for this to work correctly. Also note you have to prevent the normal submit behavior from occurring, so you also have to add the line event.preventDefault();.

And Matthew is right, you should get your data from $_POST, not $_REQUEST.

Marcovecchio
  • 1,322
  • 9
  • 19