简体   繁体   中英

Passing variable in a URL not working

So as usually I put in information in the url leading towards another page like this:

<form action="index.php?type=question">
     <input class="log-btn extra" type="submit" value="Home">
</form>

Usually it always works, I even copy pasted it because I've used the exact same url before and on the other page it works but doesn't on this one it just returns empty after the questionmark like this:

index.php?

When you want to misuse a Button as a link with URL query parameters you can do it in two ways.

In your example you try to set query parameters in the action attribute of the form . That is working as long as the method is not get , because get-parameters and URL query is exactly the same thing and submitting the form will overwrite the query with the get parameters of the form elements.

<form action="home.php?type=question" method="post">
  <input class="log-btn extra" type="submit" value="Home">
</form>    

You can also set <form method="get"> and use a button:

<form action="home.php" method="get">
  <button type="submit" name="type" value="question">Home</button>
</form>    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM