Hi guys.

My query string values are cleared (deleted) whenever I press the form 'submit button'.

It is causing my code not to function properly because I have values in the query string which I need to reuse after the submit button is clicked.

Do you know how I can fix this?

Some example code would also be helpful. 🙂

Paul.

    Is it deleting everything?

    DELETE FROM table name
    WHERE column name  = some id of what you want to delete here;
    

      The problem is because you are building the action='...' attribute in the form with just the page. If you want any exiting get parameters to be used, you would need to build the action='...' attribute with them, or if you are submitting the form to the same page that the form is on, just leave out the action attribute and the browser will automatically submit to the exact same url, including any get parameters, of the current page. If you are submitting to a different page than the form is on, you will need to build the action attribute as mentioned. If you need to build the query string part of the action attribute, see the php http_build_query() function and use the current $_GET array as its input data.

      Also, is the get parameter something like the id of the data that is being operated on by the form? If so, using a hidden form field and passing it as part of the post data may be an appropriate solution.

        pbismad wrote:

        Also, is the get parameter something like the id of the data that is being operated on by the form? If so, using a hidden form field and passing it as part of the post data may be an appropriate solution.

        But if you're sending data to the user only for them to send it back then the only thing you're achieving is giving them the chance to alter it. If you're just wanting it to persist across requests/responses then that's what session data is for.

          15 days later

          Hi Guys.

          I am still having trouble regarding the topic of this post.

          I have been working on a pagination script and to cut a long story short, it is not functioning properly because of a select element not preserving a persistent value each time the submit button is clicked.

          I tried removing the action attribute like 'pbismad' recommended (above),, and I also tried a few other things, but no luck!

          Would you guys recommend me using a 'session' instead, since nothing else is working?

          Also, I need to ask. I am already making use of a session inside another folder on my website (regarding the back end of the site).

          I was just wondering, would me using a session on the front end of the site cause problems?

          And is it common to use sessions on parts of a site that don't concern a (login/logout) admin area??

          Paul.

            Don't use session variable(s) to determine what a page's purpose is. The whole point of URLs/URIs is they determine what a page will display.

            If you have a form that's being used to determine what to display on a page, it should use method='get' (my reply above was based on a post method form.) If this is the case and you want to propagate existing get parameters (using a form would normally be for things like filters and you wouldn't want to propagate existing get parameters) you will need to pass the get parameters as hidden form fields.

            If the problem is that the pagination links are not propagating existing get parameters, you need to build the pagination links with the existing get parameters and the page number parameter. The best way of doing this is to get a copy of the $_GET into a php variable, set the page number parameter in this variable, then use http_build_query() to make the query string part of the link.

              Thanks.

              I understand what you are saying and I have tried everything.

              Here is the code to my document (everything you need).

              Please tell me what you think:

              archive.php:

              <?php
              require_once("admin/articleclass.php");
              
              
              $number = isset($_POST["article_number"]) ? (int)$_POST["article_number"] : 10;
              
              $start = isset($_GET["start"]) ? (int)$_GET["start"] : 0;
              
              
              
              
              
              ?>
              
              
              <!DOCTYPE html>
              <html lang="en">
                <head>
                  <meta charset="utf-8">
                  <meta http-equiv="X-UA-Compatible" content="IE=edge">
                  <meta name="viewport" content="width=device-width, initial-scale=1">
                  <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
                  <title>Bootstrap 101 Template</title>
              
              <!-- Bootstrap -->
              
              
              
              <link href="css/bootstrap.min.css" rel="stylesheet">
              
              <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
              <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
              <!--[if lt IE 9]>
                <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
                <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
              <![endif]-->
                </head>
                <body style="background-color: #2e1f62; margin-top: 50px;">
              
              
              
              
              
              
              <nav class="navbar navbar-default navbar-fixed-top navbar-inverse" style="background-color: #00acee; border-bottom: 1px solid brown; padding-right: 20px;">
                <div class="container-fluid">
                  <!-- Brand and toggle get grouped for better mobile display -->
                  <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false" style="border: 1px solid black;">
                      <span class="sr-only">Toggle navigation</span>
                      <span class="icon-bar" style="border: 1px solid black;"></span>
                      <span class="icon-bar" style="border: 1px solid black;"></span>
                      <span class="icon-bar" style="border: 1px solid black;"></span>
                    </button>
              
              </div>
              
              <!-- Collect the nav links, forms, and other content for toggling -->
              <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
              
              
                <ul class="nav navbar-nav navbar-right" style="font-size: 15px; font-weight: bold;">
                  <li><a href="home.php" style="color: #ec008b !important;">Home</a></li>
              			        <li><a href="about.php" style="color: #ec008b !important;">About</a></li>
              					<li><a href="news.php" style="color: #ec008b !important;">Latest News</a></li>
                  <li class="dropdown">
                    <a href="articles.php" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" style="color: white !important; background-color: rgba(255,0,0,0.2) !important; font-style: italic; text-decoration: underline;">Articles<span class="caret"></span></a>
                    <ul class="dropdown-menu">
                      <li><a href="archive.php" style="color: black !important;">Article Archive</a></li>
                      <li><a href="reviews.php" style="color: black !important;">Reviews</a></li>
                    </ul>
                  </li>
              <li><a href="contact.php" style="color: #ec008b !important;">Contact</a></li>
              
              
                </ul>
              </div><!-- /.navbar-collapse -->
                </div><!-- /.container-fluid -->
              </nav>
              
              
              <div class="col-lg-12" style="clear: both; background-color: #ccddcc;">  
              
              <img src="images/logo2.jpg" class="img-responsive" style="margin-left: auto; margin-right:auto; border: 1px solid black; border-bottom: 0px;">
              </div> 
              
              
              
              
              
              <div class="col-lg-12" style="height: 15px; background-color: #ccddcc; border-top: 1px solid black;"></div>  
              
              
              
                <div class="col-lg-12 socicons1" style="text-align: center; margin-bottom: 40px; margin-top: 40px;"><a href="https://www.linkedin.com/in/chris-thornley-05482b90/" target="_blank"><img src="images/linkedin.png"></a> <a href="https://twitter.com/ConsHeritage" target="_blank"><img src="images/twitter.png" style="margin-left: 35px;"></a></div>
              
              <div class="col-lg-12 col-md-12 socicons2" style="margin-bottom: 40px; position: absolute; text-align: right;"><a href="https://www.linkedin.com/in/chris-thornley-05482b90/" target="_blank" style="text-align: right;"><img src="images/linkedin.png"></a><br><br> <a href="https://twitter.com/ConsHeritage" target="_blank" style="text-align: right;"><img src="images/twitter.png"></a></div>
              
              
              
              
                <div class="col-lg-10 col-lg-offset-1 col-md-10 col-md-offset-1 col-sm-12 col-xs-12" style="background-color: #ccddcc; border: 1px solid black; margin-top: 30px;">
              
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="margin-top: 50px; margin-bottom: 70px;">
                <div class="col-lg-4 col-lg-offset-4 col-md-4 col-md-offset-4 col-sm-4 col-sm-offset-4" style="border: 1px solid black; border-radius: 25px;">
                <p style="text-align: center; font-size: 40px; margin-top: 5px;">Article Archive</p>
                </div>
                </div>
              
              
              
                <h1 style="text-align: center; margin-top: 60px; margin-bottom: 50px; text-decoration: underline; font-size: 30px;">Conservation & Heritage In The UK</h1>  
              
              
              
                <h2 style="text-align: center; font-size: 22px; text-decoration: underline; margin-top: 60px; margin-bottom: 60px;">Providing You With The Latest Information And News In Conservation & Heritage</h2>
              
              
              
              
              
              
              
              <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="text-align: center;">  
              
              
              
              <form method="post" style="margin-bottom: 60px;">
              
              <label for="article_number">Display: </label>
              <select name="article_number" id="article_number">
              <option value="10">10 Articles</option>
              <option value="20">20 Articles</option>
              </select>
              
              <input type="submit" name="sendme" id="send_me" value="Update Results">
              
              </form>  
              
              
              <?php
              
              list( $articles, $totalrows ) = article::getArticles($start, $number);
              
              
              if( $start > 0 ) {
              ?>
              <a href="archive.php?start=<?php echo max( $start - $number, 0 ) ?>">Previous</a>
              <?php
              }
              if( $start + $number < $totalrows ){
              ?>
              <a href="archive.php?start=<?php echo min( $start + $number, $totalrows ) ?>">Next</a>
              <?php
              }
              ?>
              
              
              
              
              
              <hr style=" border-top: 1px solid grey;">  
              
              </div>
              
              
              <?php
              
              
              
              foreach( $articles as $article ){
              ?>
              
              <div class="row">
              <div class="col-lg-10 col-lg-offset-1 col-md-10 col-md-offset-1">
              
              <div class="col-lg-2 col-md-2">
              <img src="admin/images/<?php echo $article->getValue("articleimg") ?>" style="width: 150px; height: 150px;">
              </div>
              
              <div class="col-lg-9 col-lg-offset-1 col-md-9 col-md-offset-1">
              <p style="font-weight: bold;"><?php echo $article->getValue("articletitle") . " " . $article->getValue("articledate") ?></p>
              <p><?php echo substr($article->getValue("articletext"), 0, 250) ?> ...</p>
              </div>
              </div>
              </div>
              
              <hr style=" border-top: 1px solid grey;">
              
              <?php
              }
              ?>  
              
              
              
              
                </div> 
              
                 <div class="col-sm-12 col-md-12 col-lg-12 col-xs-12" style="margin-top: 14px;">
              	<footer>
                <p style="font-size:15px; font-family: Arial, Helvetica, sans-serif; text-align: center;"><span style="color: cyan">Copyright &copy;<?php echo date("Y"); ?> Conservation & Heritage Journal Ltd | Designed by</span> <a href="http://panda-web-solutions-stockport.co.uk" target="_blank">Q4-Designs</a>.</p>
              </footer>
              </div> 
              
              
              
              
              <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
              <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
              <!-- Include all compiled plugins (below), or include individual files as needed -->
              <script src="js/bootstrap.min.js"></script>
                </body>
              </html>
              
              
                Write a Reply...