'HTML Javascript URL Parameters not lined up in a row by klicking second time on a next button

for test and understanding for my project: I want a php-page which shows me the current date of the week and a link which I can go one week forward. In the URL I send the date to the next side, if I have a datetime in URL (so the first "next" click) it should show me the next week and also a next-Button to go to the next week (2. week) and so on... (Background is I want have a weekcalendar (Monday to Friday) with buttons previous week and next week.)

Currently I have the problem, that the browser adds in the url my sended date as a added row. But I want only one date and not the previous sended dates before.

Currently: HTTPPAGENAME/?next=1653915514?next=1653915516

If i clicked to times on next. Wrong Example

But I only want only: HTTPPAGENAME/?next=1653915516

when I click for two times.

The rest of the code is not finished, currently it is only the url-row-think.

Whats the clue on that?

<?php
    date_default_timezone_set("Europe/Berlin");
    $weekdate = time(); 
    
    $tmpstringurl = strtotime("+ 1 week", $weekdate);

if(isset($_GET['next'])) {
//Test not finished
    $tmpstringurl = strtotime("+ 1 week", $weekdate);

} else {
//Test not finished
    $tmpstringurl = strtotime("+ 1 week", $weekdate);
}

?>

<!DOCTYPE html>
<html>
    <body>

<p><label>Date: <?php echo date("d.m.Y", $weekdate) ?></label></p><br/>

<a href="" onclick="location.href=this.href+'?next='+<?php echo $tmpstringurl ?>;return false;">One week more</a>

</body>
</html>


Solution 1:[1]

I have re coded your snippet below.

<?php
    # By Ajmal PraveeN (AP)
    date_default_timezone_set("Europe/Berlin");
    $weekdate = time(); 
    
    $tmpstringurl = strtotime("+ 1 week", $weekdate);

if(isset($_GET['next'])) {
//Test not finished
    $tmpstringurl = strtotime("+ 1 week", $weekdate);

} else {
//Test not finished
    $tmpstringurl = strtotime("+ 1 week", $weekdate);
}

?>

<!DOCTYPE html>
<html>
    <body>

<p><label>Date: <?php echo date("d.m.Y", $weekdate); ?></label></p><br/>

<a href="/?next=<?php echo $tmpstringurl; ?>" title="One week more">One week more</a>

</body>
</html>

If this is useful upvote.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ajmal Praveen