Kat013 Posted October 14, 2009 Share Posted October 14, 2009 Hi folks, I'd like to put several buttons on a page that assemble their own urls, as shown below. I have drastically simplified it from what I actually want to accomplish, partly to try to figure it out on my own and partly for ease of getting help. There is some file I/O in php I would like to accomplish on the processing page, so I don't want to resort to javascript. The problem is that my processing page is acting like it can't read the value passed to it in the url. <form action="" method="post"> <p> <input type="button" value="Foo" onclick="location.href= 'processIt.php' + '?' + 'number=foo32';" /> <input type="button" value="Bar" onclick="location.href= 'processIt.php' + '?' + 'number=bar32';" /> </p> </form> ... and then process them with: <?php $itemNumber=$_POST['number']; echo "<p>Item Number: ".$itemNumber."</p>"; ?> $itemNumber appears to have no value, even though the url assembles correctly, ex: processIt.php?number=foo32 I just get "Item Number:" on the page, and that's all. I've been googling for a couple of hours on this. Any help appreciated. Link to comment https://forums.phpfreaks.com/topic/177628-solved-multiple-buttons-w-onclicklocationhref-and-_post-how/ Share on other sites More sharing options...
ialsoagree Posted October 14, 2009 Share Posted October 14, 2009 POST should be GET? <?php $itemNumber=$_GET['number']; echo "<p>Item Number: ".$itemNumber."</p>"; ?> PS. because you're using double quotes you don't need to remove the variable from the string. In fact, if you're going to remove the variable from the string, you shouldn't use double quotes because it takes (marginally) longer to process (the string has to be parsed by PHP, but the variable was removed from the string so it's parsing that string for no reason wasting processing cycles). This works the same way, and makes the double quotes not redundant. <?php $itemNumber=$_POST['number']; echo "<p>Item Number: $itemNumber</p>"; ?> Link to comment https://forums.phpfreaks.com/topic/177628-solved-multiple-buttons-w-onclicklocationhref-and-_post-how/#findComment-936552 Share on other sites More sharing options...
Kat013 Posted October 14, 2009 Author Share Posted October 14, 2009 Yep, changing it to GET works. Thank you. And, thanks for the string formatting tip. Link to comment https://forums.phpfreaks.com/topic/177628-solved-multiple-buttons-w-onclicklocationhref-and-_post-how/#findComment-936562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.