Jump to content

[SOLVED] Advice on using POST or GET


graham23s

Recommended Posts

Hi Guys,

 

on the forum i'm developing iv added a search forum option the code is:

 

echo '<center><b>Options: </b><a href="forums.php?action=search">Search Forum</a><br /><br />';

 

     $action = $_GET['action'];
     
     ####################################################################################
     if ($action == "search") {
     
     ## isset code ######################################################################
     if(isset($_POST['submit'])) {
     
     echo '<br /><center><h4>Search Results</h4></center>';
     include("includes/footer.php");
     exit;
     
     
     } else {
          
        echo '<br /><center><h4>Search Forums</h4></center>';
        echo '<table width="300" border="1" cellpadding="0" cellspacing="0" />
              <form action="" method="POST" />
              <th align="center" bgcolor="#004E98" /><font color="#ffffff">Type In Keywords To Search Forum</th>
              </tr>
              <tr>
              <td align="center"><input type="text" name="search_forum" size="40" /></td>
              </tr>
              <tr>
              <td align="right" bgcolor="#004E98" /><input type="submit" name="submit" value="Search Forum" /></td>
              </table></form><br />';
              
        include("includes/footer.php");
        exit;
        
     }
     ## isset code ######################################################################     

 

i was wondering if i could use POST instead of GET when the form is submitted is there a preference you guys would choose?

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/55819-solved-advice-on-using-post-or-get/
Share on other sites

my version

 

<?php

     if ($_GET['action'] == "search") {
     
     ## isset code ######################################################################
     if(isset($_POST['submit'])) {
     
     echo '<br /><center><h4>Search Results</h4></center>';
     include("includes/footer.php");
     exit;
     
     
     } else {

?>
       
<br><center><h4>Search Forums</h4></center>';
        <table width="300" border="1" cellpadding="0" cellspacing="0" >
              <form action="<?php $_SERVER['PHP_SELF'];?cmd=search ?>" method="POST" >
              <th align="center" bgcolor="#004E98" /><font color="#ffffff">Type In Keywords To Search Forum</th>
              </tr>
              <tr>
              <td align="center"><input type="text" name="search_forum" size="40" ></td>
              </tr>
              <tr>
              <td align="right" bgcolor="#004E98" ><input type="submit" name="submit" value="Search Forum" ></td>
              </table></form><br>
              
<?php

include("includes/footer.php");
       
 if($_GET['cmd']=="search"){

//search query

}
}
?>

know were getting somewere ok.

<?php

if ($_GET['action'] == "search") {
     
if(isset($_POST['submit'])) {

echo "<br><center><h4>Search Results</h4></center>";
?>
       
<br><center><h4>Search Forums</h4></center>

<table width="300" border="1" cellpadding="0" cellspacing="0" >

<form action=" <?php $_SERVER['PHP_SELF']?>?cmd=search" method="POST" >

<th align="center" bgcolor="#004E98" /><font color="#ffffff">Type In Keywords To Search Forum</th>
              </tr>
              <tr>
              <td align="center"><input type="text" name="search_forum" size="40" ></td>
              </tr>
              <tr>
              <td align="right" bgcolor="#004E98" ><input type="submit" name="submit" value="Search Forum" ></td>
              </table></form>
              <br>
             <?php include("footer.php");?> 
<?php

if($_GET['cmd']=="search"){

//search query

}
}
  }
?>

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.