Cosimo Sguanci
Cosimo Sguanci

Reputation: 1291

Redirect user to another PHP page with parameters

I'm trying to redirect user to another PHP page to edit a SQL table, when a button is clicked. This is the code:

 $("#modificaDipinto").click(function(){

    var tipo = <?php echo json_encode($tipo_opera); ?>; 
    var codice = <?php echo json_encode($cod); ?>;
    var titolo = <?php echo json_encode($titolo); ?>;
    var annoCreaz = <?php echo json_encode($annoCreaz); ?>;
    var museo = <?php echo json_encode($museo); ?>;
    var dimensioni = <?php echo json_encode($dim); ?>;
    var tipoPittura = <?php echo json_encode($tipo_pittura); ?>;
    window.location.href = "modifica.php?codice="+codice+"&tipo="+tipo+"&titolo="+titolo+"&annoCreaz="+annoCreaz+"&museo="+museo+"&dimensioni="+dimensioni+"&tipoPitt="+tipoPittura;

 }
 });

Those variables are PHP variables declared above. I'm getting this error:

Uncaught SyntaxError: missing ) after argument list

Upvotes: 0

Views: 1650

Answers (5)

Onur Kucukkece
Onur Kucukkece

Reputation: 1748

I think you should use json_encode() in modifica.php file instead of your jquery script. This way you are sending json data in url parameters which may be causing this error.

Upvotes: 0

Ngoan Tran
Ngoan Tran

Reputation: 1527

1 redundant curly bracket in your code, remove it:

$("#modificaDipinto").click(function(){
            var tipo = <?php echo json_encode($tipo_opera); ?>; 
            var codice = <?php echo json_encode($cod); ?>;
            var titolo = <?php echo json_encode($titolo); ?>;
            var annoCreaz = <?php echo json_encode($annoCreaz); ?>;
            var museo = <?php echo json_encode($museo); ?>;
            var dimensioni = <?php echo json_encode($dim); ?>;
            var tipoPittura = <?php echo json_encode($tipo_pittura); ?>;
            window.location.href = "modifica.php?codice="+codice+"&tipo="+tipo+"&titolo="+titolo+"&annoCreaz="+annoCreaz+"&museo="+museo+"&dimensioni="+dimensioni+"&tipoPitt="+tipoPittura;
});

Upvotes: 0

Anirudh
Anirudh

Reputation: 457

I see that there is an extra flower bracket. This should work actually

$("#modificaDipinto").click(function(){

var tipo = <?php echo json_encode($tipo_opera); ?>; 
var codice = <?php echo json_encode($cod); ?>;
var titolo = <?php echo json_encode($titolo); ?>;
var annoCreaz = <?php echo json_encode($annoCreaz); ?>;
var museo = <?php echo json_encode($museo); ?>;
var dimensioni = <?php echo json_encode($dim); ?>;
var tipoPittura = <?php echo json_encode($tipo_pittura); ?>;
window.location.href = "modifica.php?codice="+codice+"&tipo="+tipo+"&titolo="+titolo+"&annoCreaz="+annoCreaz+"&museo="+museo+"&dimensioni="+dimensioni+"&tipoPitt="+tipoPittura;});

If this does not work, you can use PHP SESSION variables in order to pass variables to one page to another

Upvotes: 0

Rohit Bajaniya
Rohit Bajaniya

Reputation: 41

$("#modificaDipinto").click(function(){

    var tipo = <?php echo json_encode($tipo_opera); ?>; 
    var codice = <?php echo json_encode($cod); ?>;
    var titolo = <?php echo json_encode($titolo); ?>;
    var annoCreaz = <?php echo json_encode($annoCreaz); ?>;
    var museo = <?php echo json_encode($museo); ?>;
    var dimensioni = <?php echo json_encode($dim); ?>;
    var tipoPittura = <?php echo json_encode($tipo_pittura); ?>;
    window.location.href = "modifica.php?codice="+codice+"&tipo="+tipo+"&titolo="+titolo+"&annoCreaz="+annoCreaz+"&museo="+museo+"&dimensioni="+dimensioni+"&tipoPitt="+tipoPittura;


 });

Upvotes: 0

imprezzeb
imprezzeb

Reputation: 716

You have extra } closing curly brace.

Upvotes: 2

Related Questions