Reputation: 607
I've got an advanced parameterized query, the user sets the parameters and accordingly the query is build. I point the action of the form to a result page and on that page I fetch values using $_POST
.
I get these values correctly but the moment I refresh the page I lose the values of $_POST
. Do I need to use $_SESSION
for this? Because I don't want so many sessions, then I had to unset all once the user has used them, so how do I do it?
Form
<form action="result.php?script_id=3&sub_script_id=1">
<label for="search_for">Search For</label>
<select id="search_for" name="contact_first_name">
<?php
while($throw_names = mysqli_fetch_array($fetch_advance_param_values)) {
?>
<option value="<?php echo $throw_names['contact_first_name']; ?>"><?php echo $throw_names['contact_first_name']; ?></option>
<?php
}
?>
</select>
<br />
</form>
results.php
<?php
$fetch_results = mysqli_query($running_db,
"SELECT rec_num, record_locked, contact_first_name, contact_last_name,
contact_mobile_no, contact_office_no FROM tbl_contacts WHERE
contact_first_name = '{$_POST['contact_first_name']}'
AND group_id_entry={$_SESSION['user_group_id']}
ORDER BY $sort_column_name $sort_order $limit_records");
?>
Don't worry, right now am directly using $_POST['contact_first_name']
in my query, this is just for test purpose, later I'll use mysqli_real_escape_string()
Upvotes: 0
Views: 152
Reputation: 24576
I don't get why you are concerned about using sessions or GET parameters. A search form is usually implemented with GET anyways.
But there is another option: save the search itself in the database (then a POST form actually makes sense):
searches
table/searches/?id=1234
searches
table and execute itAt first glance this solution looks a bit overkill but it offers new possibilities like caching a search result or offer the user to save favorite searches. So there are scenarios where this approach makes sense.
Upvotes: 1
Reputation: 28742
In the first page where the post is sent to:
setcookie('searchquery','I want cookies');
in page 2
if(isset($_COOKIE['searchquery']))
{
$search = mysqli_real_escape_string($link,$_COOKIE['searchquery']);
}
Upvotes: 0