Skip to content
Advertisement

pass parameters in url via php

i am tying to pass some parameters in my URL via php. Below is my code i have tried.

<button  onclick="window.location.href='process2.php?name=' .$fname. '&Usrname=' .$name "  style="border-radius:5px;margin-right:10%;font-size:20px;box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);background-color:#d29dfa">

i guess there is some errors with the qoutes. how to solve it?

Advertisement

Answer

Instead of window.location.href which will return the current URL from the address bar, you can use window.location.assign() which will open a new document for a given address.

Check below:

<?php
  echo '<button onclick="window.location.assign("process2.php?name='.$fname.'&Usrname='.$name.'");" style="border-radius:5px;margin-right:10%;font-size:20px;box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);background-color:#d29dfa">';
?>
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement