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
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
Share on other sites

<?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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.