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

$action = $_GET['action']; <<< dont need this

   

    ####################################################################################

    if ($action == "search") {

 

 

to this

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

 

}

Link to comment
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

}
}
?>

Link to comment
Share on other sites

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

}
}
  }
?>

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.