Jump to content

Problem with PHP code


Fruddy

Recommended Posts

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

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

 

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.