I have a form
to enter a match number and submit via PHP GET
to the url, say test.php?match=
I added arrows for ease of use (time is important for the end user) that go up one match and down one match, and they work OK as long as you don't input a number first. The arrows add the number OK and I can start from 0 and go up, but if I start on another number it works once but deletes the number from the URL (for example, navigating to test.php?match=3
and pressing right arrow displays match 4 but the URL is changed to test.php?match=
)
Here is my code:
<?php
$next = $_GET["match"] + "1";
$last = $_GET["match"] - "1";
echo "<form action=\"test.php\" method=\"GET\">
Match<br>
<input style=\"font-size:24px;\" autofocus=\"autofocus\" type=\"number\" size=\"4\" name=\"match\" value=\"" . $_GET["match"] . "\">
<a href=\"sql.php?match=\"><button style=\"font-size:24px;\">Show All</button></a>
<a href=\"sql.php?match=" . $last . "\"><button style=\"font-size:24px;\"><</button></a>
<a href=\"sql.php?match=" . $next . "\"><button style=\"font-size:24px;\">></button></a>
<input style=\"font-size:24px;\" type=\"submit\" value=\"Submit\">
</form>";
?>
Thanks!
Try to replace your form with this:
echo "<form action= 'test.php' method='GET'>
Match<br>
<input style='font-size:24px;' autofocus='autofocus' type='number' size='4' name='match' value='" . $_GET["match"] . "'>
<a href='sql.php?match='><button style='font-size:24px;'>Show All</button></a>
<a href='sql.php?match=" . $last . "' style = 'padding: 5px; border-radius: 5px; background: rgb(240, 240, 240); border: 1px solid silver;'><<<</a>
<a href='sql.php?match=" . $next . "' style = 'padding: 5px; border-radius: 5px; background: rgb(240, 240, 240); border: 1px solid silver;'>>>></a>
<input style='font-size:24px;' type='submit' value='Submit'>
</form>";
The <a>
is not directing you to the link if the <button>
inside it is clicked. It appears that you are clicking the <button>
and not the <a>
. So as a suggestion, you can style you <a>
so that it may appear as a button.
Maybe something like this is what you want:
<?php
$next = $_GET["match"] + "1";
$last = $_GET["match"] - "1";
?>
<form action="" method="GET">
Match<br>
<input style="font-size:24px;" autofocus="autofocus" type="number" size="4" name="match" value="<?php echo $_GET['match'] ?>">
<button style="font-size:24px;"><a href="?" style="text-decoration:none; color:#000;">Show All</a></button>
<button style="font-size:24px;"><a href="?match=<?php echo $last ?>" style="text-decoration:none; color:#000;"><</a></button>
<button style="font-size:24px;"><a href="?match=<?php echo $next ?>" style="text-decoration:none; color:#000;">></a></button>
<input style="font-size:24px;" type="submit" value="Submit">
</form>
I think it better to separate php and html form (don't echo the form, but only the value what you want to pass)