feck Posted January 19, 2007 Share Posted January 19, 2007 Hi,Is there a way to have a simple page that post a variable back too itself and display that varaible on the page.Using a button to increment a variable and then redisplay the new value Link to comment Share on other sites More sharing options...
Anders Moen Posted January 19, 2007 Share Posted January 19, 2007 Do you mean something like this? <?phpif(isset($_POST['submit'])) {echo "Your name is $_POST[name]<br />and your email is <a href='mailto:$_POST[email]'>$_POST[email]</a>";}else {echo "<form action='' method='post'><p>Name<br /><input type='text' name='name' /></p><p>Email<br /><input type='text' name='email' /></p><p> <br /><input type='submit' name='submit' value='Submit' /></p></form>";}?> I tested the code, and it works. It's very similiar to the one in the PHP section at W3Schools, just that I made this on my own right now Link to comment Share on other sites More sharing options...
feck Posted January 20, 2007 Author Share Posted January 20, 2007 Sorry andersmoen,what I'm thinking of is something that will diplay the amount of times you click a button, by posting a variable back to itself after every click and redisplay the new value.I not too sure this can be done without using javascript, maybe I'm wrong. Link to comment Share on other sites More sharing options...
Anders Moen Posted January 20, 2007 Share Posted January 20, 2007 Aha. Maybe you mean the count() variable in PHP. Read about it at php.net. Link to comment Share on other sites More sharing options...
feck Posted January 20, 2007 Author Share Posted January 20, 2007 Solved it: <?phpif(isset($_POST['count'])){ $var=++$_POST['count']; }else{ $var= '1'; }echo "<form action='testButtonClick.php' method='post'><p>Counter:<br /><input type='text' name='count' value='$var'/></p><br /><input type='submit' name='submit' value='Submit' /></p></form>";?> Pretty useless piece of code, I know, but just wanted too see how it could be done.Is there no other way of doing this apart from a full page refresh? Link to comment Share on other sites More sharing options...
Anders Moen Posted January 20, 2007 Share Posted January 20, 2007 Hmm, I guess there are. You can use <form action='' method='post'>. Then you will be on the same site all the time. If that's what you mean. Link to comment Share on other sites More sharing options...
feck Posted January 20, 2007 Author Share Posted January 20, 2007 The testButtonClick.php was the script itself, did'nt know you could leave this out and achieve the same thing in the post method. Thanks for that, but both way's still require a full refresh. Link to comment Share on other sites More sharing options...
Anders Moen Posted January 20, 2007 Share Posted January 20, 2007 Okay, you could have told us in the post before you know :)I guess you'll gonna have to find something else than the count() then. Search for ip counter at google.com or something. Maybe you'll get something then Link to comment Share on other sites More sharing options...
Escee Posted January 20, 2007 Share Posted January 20, 2007 The testButtonClick.php was the script itself, did'nt know you could leave this out and achieve the same thing in the post method. Thanks for that, but both way's still require a full refresh.If you don't want to refresh your page like the F5 way.. you can take a look at AJAX (Google some tuts & W3Schools tuts offcourse) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now