2 Replies - 125 Views - Last Post: 25 November 2017 - 03:45 PM

#1 sonar87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 04-February 08

Link that preserves post data already sent to page plus send one more

Posted 25 November 2017 - 03:26 PM

I'm needing to reload a page that has already had POST data sent, and preserving that data through the reload and also sending one more value. This is for search results page, you enter text, POST data of the search keywords is then through a form. The page reloads now showing results based on that data. But then I want a link that can be clicked to change ordering of the search results, by id, name, etc, which is what I'm trying now.

I'm sending the keyword search data from the previous page with a form like this

<form action = "search.php" method = "post">
<lable for = "keyword">Search Term: </lable>
<input type = "search" name = "kname" id = "keyword">
<input type = "submit" value = "Search">
</form>


Then on the page that needs refreshed pulling it into some php to do DB query based on that

$keyword = $dbcon->real_escape_string($_REQUEST['keyword']);

$result = $dbcon->query("SELECT * FROM Listing WHERE title LIKE '%$keyword%' ORDER BY title");


// Echo out some results and html for layout


I want couple links somewhere above echoed out results to change their order. Thought I'd replace title in ORDER BY with a php variable set to use choice.

I found
href="javascript:window.location.reload(true)"


for reloading and preserving the POST data that is already there but I need to get one more value over for the ordering type sent and note sure how.

Is This A Good Question/Topic? 0
  • +

Replies To: Link that preserves post data already sent to page plus send one more

#2 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6444
  • View blog
  • Posts: 26,066
  • Joined: 12-December 12

Re: Link that preserves post data already sent to page plus send one more

Posted 25 November 2017 - 03:40 PM

Use parameterized queries, you code is open to SQL injection.

As you are just performing a simple search why do you need to post the data? If you use get it is easy enough just to add additional value(s) to the querystring to enable sorting.
Was This Post Helpful? 0
  • +
  • -

#3 sonar87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 04-February 08

Re: Link that preserves post data already sent to page plus send one more

Posted 25 November 2017 - 03:45 PM

Thanks, I'll look that up.

And used the post because that with the form was the only way I knew to get input.


EDIT: Switched to get in from and looked. Ok... I now see... cool.

This post has been edited by sonar87: 25 November 2017 - 03:49 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1