Steve Clarke
Steve Clarke

Reputation: 99

php create button url from script

I currently use a script to generate two variables that need to be passed into a url. The two variables are generated from an array. What i'm looking to do is similar to a 'next' button that when the user clicks, it takes the user to the generated url

my_page.html

<form action="next_to_go.php" method="get">
<button id="next_to_go" class="btn btn-warning" type="submit">Next To Go</button>
</form>

next_to_go.php currently generates two vars: $code and $num for the url

$my_url = '/today.php?code='.$code.'&num='.$num;
header('location:'.$my_url);

I've tried using... which works when testing 'next_to_go.php' by itself. but when clicking the button within the my_page.html, it does not work. also, i'm still searching (and learning) for an ajax solution... any help would be greatly appreciated!

edit: using ajax with the next_to_go.php echoing the url

$("#next_to_go").click(function(){

    $.ajax({
        type: 'POST',
        url: 'next_to_go.php',
        success: function(data) {
            window.location = href;
        }
    });
});

Upvotes: 1

Views: 78

Answers (1)

Steve Clarke
Steve Clarke

Reputation: 99

was easier than i made it out to be..

within the html:

<a href="next_to_go.php" class="btn">Next</a>

within the php:

header('location:'.$my_url);

Upvotes: 1

Related Questions