Jump to content

PHP Get Message


Ell20

Recommended Posts

Hi,

 

I have some code which includes some GETS, however each GET contains a submit button which display a message and performs a task.

This is working fine however once the submit button is pressed the current GET is lost and it returns to the original page from which the message is also display on.

 

How do I adapt the code so that when the submit button is pressed the message is displayed in the current GET and it doesnt refresh back to the original page?

 

<?php
if (isset($_POST['submit'])) {
echo "<center>This is test 1</center>";
}
if (isset($_POST['submit2'])) {
echo "<center>This is test 2</center>";
}
?>

<table align="center" border="1" cellpadding="0" cellspacing="0" width="60%" class="game">
<tr>
<td colspan="4">
Testing
</td>
</tr>
<tr height="50px" align="center">
<td>
<a href='<?=$_SERVER['PHP_SELF']."?";?>&mode=test1'>Test1</a>
</td>
<td>
<a href='<?=$_SERVER['PHP_SELF']."?";?>&mode=test2'>Test2</a>
</td>
</table>

<?php if (isset($_GET['mode']) && $_GET['mode'] == 'test1') { ?>
<table width="60%" align="center" cellspacing="0" border="0" class="game">
<tr>
<th width="50%">Testing 1</th>
</tr>
<tr>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<td width="33%" align="center"><input name="submit" type="submit" value="Test" /></td>
</form>
</tr>
</table>
<?php } ?>

<?php if (isset($_GET['mode']) && $_GET['mode'] == 'test2') { ?>
<table width="60%" align="center" cellspacing="0" border="0" class="game">
<tr>
<th width="50%">Testing 2</th>
</tr>
<tr>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<td width="33%" align="center"><input name="submit2" type="submit" value="Test 2" /></td>
</form>
</tr>
</table>
<?php } ?>

 

Appreciate any help

Link to comment
Share on other sites

You need to append the GET value to the form action. Try this:

 

<?php
if (isset($_POST['submit'])) {
echo "<center>This is test 1</center>";
}
if (isset($_POST['submit2'])) {
echo "<center>This is test 2</center>";
}
?>

<table align="center" border="1" cellpadding="0" cellspacing="0" width="60%" class="game">
<tr>
<td colspan="4">
Testing
</td>
</tr>
<tr height="50px" align="center">
<td>
<a href='?mode=test1'>Test1</a>
</td>
<td>
<a href='?mode=test2'>Test2</a>
</td>
</table>

<?php if (isset($_GET['mode']) && $_GET['mode'] == 'test1') { ?>
<table width="60%" align="center" cellspacing="0" border="0" class="game">
<tr>
<th width="50%">Testing 1</th>
</tr>
<tr>
<form action="?mode=test1" method="post">
<td width="33%" align="center"><input name="submit" type="submit" value="Test" /></td>
</form>
</tr>
</table>
<?php } ?>

<?php if (isset($_GET['mode']) && $_GET['mode'] == 'test2') { ?>
<table width="60%" align="center" cellspacing="0" border="0" class="game">
<tr>
<th width="50%">Testing 2</th>
</tr>
<tr>
<form action="?mode=test2" method="post">
<td width="33%" align="center"><input name="submit2" type="submit" value="Test 2" /></td>
</form>
</tr>
</table>
<?php } ?>

 

....I also took out the PHP_SELFs as you can get away without them

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.