Passing of values by post of an input via javascript to php does not work when changing hosting

0

The input of the form is:

         <form name="afegir" action="funcion_quimics.php" method="post" onSubmit="return valida_afegir(this)" enctype="multipart/form-data" accept-charset=utf-8 >             
        <br><br>
        <?
        $descripciones=$conexion->query("SELECT * FROM tiposenvase");
        $descripciones = $descripciones->fetch_array();

        while($fila = $resultado->fetch_array()){
            ?>
            <fieldset style=" border-radius:5px; margin-left:2px; margin-right:2px;">
            <?
            $fila_aux = str_replace(".","_",$fila['idRes']);
            echo "<div> ".$fila['idRes']."<h4 style='vertical-align:middle; margin-left:5px; display:inline'> - ".$fila['denominacion'].".<img id='im".$fila_aux."' src='plus.png' style='cursor:pointer; padding-left:10px; vertical-align:bottom; height:24px; width:24px;' onclick=\"showdiv('".$fila_aux."')\" /></h4> </div><br>
        <div id='".$fila_aux."' style='display:none'>";
        ////////////////////////////////////
        //Gestion de los campos de envases//
        ////////////////////////////////////
        $NoRetorn = '';
        $Retorn = '';
        switch ($fila['tipus']) {
            case '1'://Només té no retornables
                $Retorn = 'disabled';
                break;
            case '2'://Només té retornables
                $NoRetorn = 'disabled';
                break;
        }
        ?>
        <table>
        <tr>
            <td class="border_right">Descripció i detall del residu(2)</td>
        <?
            $finfo = $resultado->fetch_fields();
            for ($i=3; $i < count($finfo); $i++) { 
                $aux=$finfo[$i]->name;
                if ($fila[$aux]==1){
                    echo "<td class='border_right'>".$descripciones[$aux]."</td>";
                }
            }
        ?>
        </tr>
        <tr>

        <?
            echo "<td><input type='text' name='info_".$fila_aux."' value=''></td>";
            //echo "<input type='hidden' name='llista[]' value='".$fila_aux."'>";
            //http://stackoverflow.com/questions/10283755/disable-submit-functionality-for-all-forms-on-a-html-page
            for ($i=3; $i < count($finfo); $i++) { 
                $aux=$finfo[$i]->name;
                if (($aux=='ENV1L') || ($aux=='ENV2L')){
                    $disabled = "disabled title='Aquest envàs no pot ser retornable'";
                } else {
                    $disabled = '';
                }
                $rest = substr($aux, 3);
                if ($fila[$aux]==1){
                    echo "<td><table><tr>";
                    echo "<td><input type='text' id='n".$rest."_".$fila_aux."' name='n".$rest."_".$fila_aux."' value='' size='3' $NoRetorn ></td></tr>";
                    echo "<tr><td><input type='text' id='r".$rest."_".$fila_aux."' name='r".$rest."_".$fila_aux."' value='' size='3' style='background-color:#CEFFE9' $disabled $Retorn ></td>";
                    echo "</tr></table></td>";
                }
            }
        ?>
        </tr>
        </table>
        <?
        echo "</div>";
        ?> </fieldset> <?
        }
        ?>
        <br>
        <center><img src="../images/separador_440px.gif" alt="" width="434px" height="1px"></center>
        <br>
        <?
        /////////////////////////////////////////////
        ///NUEVOS RESIDUOS CON EXCEL INDEPENDIENTE///
        /////////////////////////////////////////////
        $consulta_2 = "SELECT * FROM descripciones2";
        $resultado_nuevos=$conexion->query($consulta_2);

        while($fila = $resultado_nuevos->fetch_array()){
            ?>
            <fieldset style=" border-radius:5px; margin-left:2px; margin-right:2px;">
            <?
            $fila_diferentes = str_replace(".","_",$fila['idRes']);
            echo "<div> ".$fila['idRes']."<h4 style='vertical-align:middle; margin-left:5px; display:inline'> - ".$fila['denominacion'].".<img id='im".$fila_aux."' src='plus.png' style='cursor:pointer; padding-left:10px; vertical-align:bottom; height:24px; width:24px;' onclick=\"showdiv('".$fila_diferentes."')\" /></h4> </div><br>
        <div id='".$fila_diferentes."' style='display:none'>";
        ////////////////////////////////////
        //Gestion de los campos de envases//
        ////////////////////////////////////
        ?>
        <table>
        <tr>
            <td class="border_right">Descripció i detall del residu(2)</td>
        <?
            $finfo = $resultado_nuevos->fetch_fields();
            for ($i=2; $i < count($finfo); $i++) { 
                $aux=$finfo[$i]->name;
                if ($fila[$aux]==1){
                    echo "<td class='border_right'>".$descripciones[$aux]."</td>";
                }
            }
        ?>
        </tr>
        <tr>

        <?
            echo "<td><input type='text' name='info_".$fila_diferentes."' value=''></td>";
            //echo "<input type='hidden' name='llista[]' value='".$fila_aux."'>";

            for ($i=2; $i < count($finfo); $i++) { 
                $aux=$finfo[$i]->name;
                $rest = substr($aux, 3);
                if ($fila[$aux]==1){
                    echo "<td>";
                    echo "<input type='text' id='new".$rest."_".$fila_diferentes."' name='new".$rest."_".$fila_diferentes."' value='' size='5'>";
                    echo "</td>";
                }
            }
        ?>
        </tr>
        </table>
        <?
        echo "</div>";
        ?> </fieldset> <?
        }
        ?>
        <br>
        <div id="llista_id">
        </div>
        <?
        if ($result_hab['habilitat']==0){
        ?>
        <center><input type="submit" name="afegir_quimics" value="Acceptar" disabled="disabled"></center>
        <?
        } else {
        ?>
        <script>
            alert ("El búnquer es troba deshabilitat en aquests moments.");
        </script>
        <?
        }
        ?>
        <br>
        </form>

Array in javascript that I'll pass to php:

var variables= new Array("r5LE_","r5LA_","r10LE_","r10LA_","r25LG_","r30LB_","r60LB_","r120LB_","rCPLASTICO_","r8LSEG_","r11LSEG_","rUnidades","rCFILTRE_","n1L_","n2L_","n5LE_","n5LA_","n10LE_","n10LA_","n25LG_","n30LB_","n60LB_","n120LB_","nCPLASTICO_","n8LSEG_","n11LSEG_","nUnidades_","nCFILTRE_","new60LN_","new30LN_","new10LN_","new5LN_","new3LN_","new2LN_","new1LN_");

Then in a javascript

function valida_afegir(){
var mutli_education = document.afegir.elements["llista[]"];
var ele ='';
var trobat = false;
var trobat2 = false;
var x=0;
var i=0;

if (mutli_education.length>1){
    while ((x<mutli_education.length)/*&&(trobat==false)*/&&(trobat2==false)){
        i=0;
        while ((i<variables.length)/*&&(trobat==false)*/&&(trobat2==false)){
            ele=variables[i] + mutli_education[x].value;
            if (aux=document.getElementById(ele)){
                if (vacio(aux.value) == true){
                    trobat=true;

                }
                if (!/^([0-9])*$/.test(aux.value)){
                    trobat2=true;   
                }
            }
            i++;
        }
        x++;
    }
}else {
    i=0;
    while ((i<variables.length)/*&&(trobat==false)*/&&(trobat2==false)){
        ele=variables[i] + mutli_education.value;
        aux=document.getElementById(ele);
        if (aux=document.getElementById(ele)){
            if (vacio(aux.value) == true){
                trobat=true;        
            }
         if (!/^([0-9])*$/.test(aux.value)){
            trobat2=true;   
            }
            }
        i++;
    }
}

if(trobat2==true){
    alert("El valor " + aux.value + " no es un nombre");
    return false;
        }
if (trobat==false){
    alert ("El formulari no pot estar en blanc.");
    return trobat;
}else {
    alert ("Tot correcte.");
    return true
}

}

Then I pick it up like this and insert it in the DB in another php. It is a loop with foreach because several values can come via post, several requests of several inputs, so the foreach for each one:

if ($_POST['llista_old']){
    foreach($_POST['llista_old'] as $check) {
        $info = addslashes($_POST["info_$check"]);
        $r5Le = $_POST['r5LE_$check'];
        $r5La = $_POST['r5LA_$check'];
        $r10Le = $_POST['r10LE_$check'];
        $r10La = $_POST['r10LA_$check'];
        $r25L = $_POST['r25LG_$check'];
        $r30L = $_POST['r30LB_$check'];
        $r60L = $_POST['r60LB_$check'];
        $r120L = $_POST['r120LB_$check'];
        $rcaixa = $_POST['rCPLASTICO_$check'];
        $rcaixa2 = $_POST['rCFILTRE_$check'];
        $r8L = $_POST['r8LSEG_$check'];
        $r11L = $_POST['r11LSEG_$check'];
        $unidades = $_POST['rUnidades_$check'];

       if(!($conexion->query("INSERT INTO retornables (idSol, idRes, 5LE, 5LA, 10LA, 10LE, 25LG, 30LB, 60LB, 120LB, CPLASTICO, 8LSEG, 11LSEG, Unidades, CFILTRE) VALUES (".$_SESSION['timest'].", '$aux', '$r5Le', '$r5La', '$r10La', '$r10Le', '$r25L', '$r30L', '$r60L', '$r120L', '$rcaixa', '$r8L', '$r11L', '$unidades', '$rcaixa2')"))){
                printf("La conexión con el servidor de base de datos falló: %s\n",  $conexion->error);exit(0);

        }

}

Well this works without more in my current hosting, but in the new the post does not collect anything, it is empty in $_POST . I have tried coding themes (default server in UTF-8) but nothing. In the browser console does not show anything relevant. Any ideas?

    
asked by Multimedia 08.11.2018 в 13:02
source

1 answer

0

The solution: Use double quotes when collecting in the post:

$r5Le = $_POST["r5LE_$check"];

and in the rest of values. Later also in new hosting they changed the SQL Mode to STRICT, when in the previous one it was empty: link

With what was wrong when trying to put a value of type different from the default (NULL)

    
answered by 09.11.2018 / 15:12
source