Categories: javascript, php, html

pass parameters in url via php

1 answer

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?

Received answer to this question:
The best answer according to the author of the question:

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">';  ?>