Update URL with PHP

0

I have this PHP code:

<?php
if(isset($_POST["boton4"]))
{ 
 $finalcode = 'RV-'.createRandomPassword(); 
 header("location: ventas.php?codventa='".$finalcode."'");
}
?>

What it does is update the code and change it in the url, but nothing else changes the code and does not update it in the url, why is this happening?

    
asked by 12.07.2018 в 21:29
source

4 answers

0

The only thing that occurred to me to solve this problem was to use a bit of javascript and that way if I updated the url

function ActualizarCodigo(codigo)
{
    window.location.href = 'ventas.php?codventa=' + codigo;
}
    
answered by 19.07.2018 / 19:00
source
1

Make sure you do not have any html code above the tag. Location is with 'L' and the variable in the URL is not enclosed in quotes.

<?php
    if(isset($_POST["boton4"])) { 
     $finalcode = 'RV-'.createRandomPassword(); 
     header("Location: http://www.midominio.com/ventas.php?codventa=".$finalcode);
    } ?>
    
answered by 12.07.2018 в 21:58
1

Try this, first the "L" must be in upper case and second the gerarqui of quotes influences ...

header('Location: ventas.php?codventa='.$finalcode);

If I help you, mark it as resolved.) BY srJJ

    
answered by 12.07.2018 в 21:46
0

then friend, you should check the condition, it may be that you are not entering the condition, that's why you never generate it ... within the if you must put something to prove whether I enter or not, for example:

<?php
  if(isset($_POST["boton4"]))
  { 

   $finalcode = 'RV-'.createRandomPassword(); 
   echo "<script> console.log('$finalcode');</script>";
   //header("location: ventas.php?codventa='".$finalcode."'");
  }
?>

in this case you will be printed in console the value of variabe $finalcode (if you do not know how to remove the console from the browser with F12 and in the tabs it says console) there you will notice if it is entering the if, detail that comment the hearde so you do not redirect, because if you let it redirect you and it will not let you see. You tell me what happened.

    
answered by 12.07.2018 в 22:56