Problems in PHP call [closed]

0

I have a problem calling a program by PHP passing parameters.

Code:

<?
    print("<script language=javascript>
       alert(\" <<<  Dados Alterados com Sucesso!  >>>\");
       if($w_rec != "")
       {
           if (confirm(\"Deseja alterar as demais opções?\") == true)
           {
             location.replace(\"../sai_cada_peri/sai_frm_alte_peri.php?$w_rec+$w_cont\");
           }
           else{
            parent.location.replace(\"../sai_cada_peri/sai_alte_peri.php\");
            }
        }
        else{
            parent.location.replace(\"../sai_cada_peri/sai_alteperi.php\");
        }    
      </script>"); 
?>

In the% PHP stretch it will check whether the $w_rec % is empty, and if it is and the user confirms he will call another program passing these parameters. My problem is .. How do I pass these parameters on this call?

The call I'm referring to would be this line:

location.replace(\"../sai_cada_peri/sai_frm_alte_peri.php?$w_rec+$w_cont\");

Note * The program as a whole is only PHP .

    
asked by anonymous 09.09.2014 / 15:33

2 answers

7

Avoid mixing server and client languages in the same code

This practice makes it difficult to maintain and grease your code. Ideally, you should separate the layers of code and pass the required information via an object or as parameters to a function, for example.

Practical example:

function sucesso(w_rec, w_cont){
    alert("<<<  Dados Alterados com Sucesso!  >>>");
    if(w_rec != ""){
        if(confirm("Deseja alterar as demais opções?") == true){
            location.replace("../sai_cada_peri/sai_frm_alte_peri.php?" + Number(w_rec+w_cont));
        }else{
            parent.location.replace("../sai_cada_peri/sai_alte_peri.php");
        }
    }else{
        parent.location.replace("../sai_cada_peri/sai_alteperi.php");
    }
}

And then you pass your PHP variables to the JavaScript function:

sucesso(<?php echo $w_rec ?>, <?php echo $w_cont ?>);
    
09.09.2014 / 16:03
2

I'm sorry I was going to try to help but as I do not agree with the way you're exposed, I'd recommend recommending the following:

first: Pass content to javascript variables ... example: no html ...

<script type="text/javascript">
    var w_rec = '<?php echo $w_rec ?>';
    var w_cont = '<?php echo $w_cont ?>';
</script>

Then use the same code but in pure javascript ... any publisher can help! I think it is simpler, more intuitive and more manageable within the project.

    
09.09.2014 / 16:03