Fruddy Posted March 9, 2007 Share Posted March 9, 2007 My site: www.newcomedy.net/home PHP code: <?php if(isset($_POST['button1_x'])) echo "Button1 was pressed"; elseif(isset($_POST['button2_x'])) echo "Button2 was pressed"; else echo "None of the buttons were pressed"; ?> Even if I press button 1 or 2, the "None of the buttons were pressed" text will appear. Is there something wrong with the code? Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/ Share on other sites More sharing options...
JasonLewis Posted March 9, 2007 Share Posted March 9, 2007 are the buttons appropriatly named and are they inside a FORM tag, because they need to be and the form tag needs to be POST. Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203395 Share on other sites More sharing options...
Fruddy Posted March 9, 2007 Author Share Posted March 9, 2007 Yes I think so: <form action="index.php" method="POST"> <table align="center" border="0" cellspacing="0" cellpadding="0"><tr> <td width="898"><img border="0" width="212" height="51" src="http://www.newcomedy.net/imgs/home_06.gif"><input name="button1" type="image" src="http://www.newcomedy.net/imgs/button_01.gif"><img width="116" src="http://www.newcomedy.net/imgs/home_08.gif"><input name="button2" type="image" src="http://www.newcomedy.net/imgs/button_02.gif"><img width="234" height="51" src="http://www.newcomedy.net/imgs/home_10.gif"> </td></tr></table><table align="center" border="0" cellspacing="0" cellpadding="0"><tr><td background="http://www.newcomedy.net/imgs/home_11.gif"> <img src="http://www.newcomedy.net/imgs/home_11.gif"></td></tr></table></form> Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203397 Share on other sites More sharing options...
tauchai83 Posted March 9, 2007 Share Posted March 9, 2007 <?php if(isset($_POST['button1_x'])){ echo "Button1 was pressed"; } elseif(isset($_POST['button2_x'])){ echo "Button2 was pressed"; } else{ echo "None of the buttons were pressed"; } ?> try this instead Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203399 Share on other sites More sharing options...
JasonLewis Posted March 9, 2007 Share Posted March 9, 2007 remove the _x from the if statements. because your buttons are simply called button1 and button2 Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203405 Share on other sites More sharing options...
Fruddy Posted March 9, 2007 Author Share Posted March 9, 2007 tauchai83, didnt work :/ Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203409 Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 fully tested ok? <?php if(isset($button1_x)){ echo "Button1 was pressed"; }elseif(isset($button2_x)){ echo "Button2 was pressed"; } echo"<form method='POST' action=''> <input type='submit' name='button1_x' value='button 1'> <br> <input type='submit' name='button2_x' value='button 2'> </form>"; ?> Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203412 Share on other sites More sharing options...
JasonLewis Posted March 9, 2007 Share Posted March 9, 2007 fruddy, read my post above. i am sure it solves your problem... remove the _x from the if statements. because your buttons are simply called button1 and button2 Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203413 Share on other sites More sharing options...
Fruddy Posted March 9, 2007 Author Share Posted March 9, 2007 I've been told that they have to be there, because the input is type=image. But I tried to remove it, didnt work either.. Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203415 Share on other sites More sharing options...
Fruddy Posted March 9, 2007 Author Share Posted March 9, 2007 Redarrow then why does this form dont work?: [tt]<form action="index.php" method="POST"> <table align="center" border="0" cellspacing="0" cellpadding="0"><tr> <td width="898"><img border="0" width="212" height="51" src="http://www.newcomedy.net/imgs/home_06.gif"><input name="button1" type="image" src="http://www.newcomedy.net/imgs/button_01.gif"><img width="116" src="http://www.newcomedy.net/imgs/home_08.gif"><input name="button2" type="image" src="http://www.newcomedy.net/imgs/button_02.gif"><img width="234" height="51" src="http://www.newcomedy.net/imgs/home_10.gif"> </td></tr></table><table align="center" border="0" cellspacing="0" cellpadding="0"><tr><td background="http://www.newcomedy.net/imgs/home_11.gif"> <img src="http://www.newcomedy.net/imgs/home_11.gif"></td></tr></table></form>[/tt] Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203416 Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 There no need for the else statement if there no more button's they got to press one lol? Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203418 Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 look at the name of the button you said the button name is button1_x you got button1 Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203419 Share on other sites More sharing options...
Fruddy Posted March 9, 2007 Author Share Posted March 9, 2007 I've been told that they have to be there, because the input is type=image. But I tried to remove it, didnt work either.. Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203421 Share on other sites More sharing options...
JasonLewis Posted March 9, 2007 Share Posted March 9, 2007 i ran a test on my computer and you dont need the _x at all. Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203422 Share on other sites More sharing options...
Fruddy Posted March 9, 2007 Author Share Posted March 9, 2007 Weird, but i have tried to remove the _x, but still it doesnt work. Can it be the Form that is causing the problem? <form action="index.php" method="POST"> <table align="center" border="0" cellspacing="0" cellpadding="0"><tr> <td width="898"><img border="0" width="212" height="51" src="http://www.newcomedy.net/imgs/home_06.gif"><input name="button1" type="image" src="http://www.newcomedy.net/imgs/button_01.gif"><img width="116" src="http://www.newcomedy.net/imgs/home_08.gif"><input name="button2" type="image" src="http://www.newcomedy.net/imgs/button_02.gif"><img width="234" height="51" src="http://www.newcomedy.net/imgs/home_10.gif"> </td></tr></table><table align="center" border="0" cellspacing="0" cellpadding="0"><tr><td background="http://www.newcomedy.net/imgs/home_11.gif"> <img src="http://www.newcomedy.net/imgs/home_11.gif"></td></tr></table></form> Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203426 Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 Look at this properly you dont need button's and forms do it properly ok? Fully tested. test_button.php <?php if($_GET['cmd']=='button1_x'){ echo "Button1 was pressed"; }elseif($_GET['cmd']=='button2_x'){ echo "Button2 was pressed"; } ?> <table align="center" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="898"> <img border="0" width="212" height="51" src="http://www.newcomedy.net/imgs/home_06.gif"> <a href="test_button.php?cmd=button1_x"><img border="0"src="http://www.newcomedy.net/imgs/button_01.gif"></a> <img border="0" width="116" src="http://www.newcomedy.net/imgs/home_08.gif"> <a href="test_button.php?cmd=button2_x"><img border="0" src="http://www.newcomedy.net/imgs/button_02.gif"> <img border="0" width="234" height="51" src="http://www.newcomedy.net/imgs/home_10.gif"> </td> </tr> </table> <table align="center" border="0" cellspacing="0" cellpadding="0"> <tr> <td background="http://www.newcomedy.net/imgs/home_11.gif"> <img src="http://www.newcomedy.net/imgs/home_11.gif"> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/41954-problem-with-php-code/#findComment-203431 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.