How to keep already-set GET parameter values on form submission? - php

I have a URL : foo.php?name=adam&lName=scott, and in foo.php I have a form which gives me values of rectangleLength & rectangleBreadth with a submit button.
When I click this submit button with form action as $_SERVER['REQUEST_URI'], I get this result URL: foo.php?rectangleLength=10&rectangleBreadth=5 (these values have been filled in by the user).
Notice that I am losing my previous values name & lName from the URL.
How can I keep them?
Also, keep in mind that I have to come back to foo.php and if the user wants to submit the form again then the length and breadth values should change.

You can add two hidden fields in the form on the first target site, blabla.php in your case:
<form ...>
<input type="hidden" name="name" value="<?php echo htmlspecialchars($_GET['name']);?>">
<input type="hidden" name="lName" value="<?php echo htmlspecialchars($_GET['lName']);?>">
<!-- rest of the form here -->
</form>
For a dynamic solution, use a foreach loop:
<?php
foreach($_GET as $name => $value) {
$name = htmlspecialchars($name);
$value = htmlspecialchars($value);
echo '<input type="hidden" name="'. $name .'" value="'. $value .'">';
}
?>
You may consider locking the dynamic approach down to a list of known possible keys:
<?php
$keys = array('name', 'lName', ...);
foreach($keys as $name) {
if(!isset($_GET[$name])) {
continue;
}
$value = htmlspecialchars($_GET[$name]);
$name = htmlspecialchars($name);
echo '<input type="hidden" name="'. $name .'" value="'. $value .'">';
}
?>

A simpler solution to keep the URL unchanged by using http_build_query
<form action="<?php echo $_SERVER["PHP_SELF"] . '?'.http_build_query($_GET); ?>" ...
..
..

There are different ways to do this. All of them write the parameters they receive into a file, memory, or a database and retrieve them later with a key
The easiest method is something like a session variable: http://php.net/manual/en/features.sessions.php
The main setup is something like this (caution: that is unsecure code, make sure you only add session variables you want to keep, and sanitize user input!):
<?php
session_start();
foreach ($_GET as $key=>$value) {
$_SESSION[$key]=>$value;
}
?>
and now, as long as the user does not close the browser, you can access these variables with $_SESSION[varname];

Once, I needed sorting the results in a table keeping the search results coming from GET. I did like that:
unset($_GET['sort']); // sort param is removed, otherwise there will be created many sort params
$url = http_build_query($_GET);
echo "<a href='?".$url."&sort=title'>Title</a>";
echo "<a href='?".$url."&sort=author'>Author</a>";

To handle query with arrays:
foreach (explode("\n", http_build_query($query, '', "\n")) as $keyValue) {
[$key, $value] = explode('=', $keyValue, 2);
$key = htmlspecialchars(urldecode($key), ENT_COMPAT | ENT_HTML5);
$value = htmlspecialchars(urldecode($value), ENT_COMPAT | ENT_HTML5);
echo '<input type="hidden" name="' . $key . '" value="' . $value . '"' . "/>\n";
}

Following code works for my project. Hope it help some.
1. In menu (calling html) I call VendorSearch.php. variable fromvs is used in URL.
2. The target php VendorSearch.php will do different jobs based on the value of $_GET['fromvs']
3. In VendorSearch.php, aftersession_start(),
$srchfor ="";
$fromwhat = $_GET['fromvs'];
$_SESSION['fromwhat'] = $fromwhat;
//save value to $VS
$vs = $fromwhat;
3. Use hidden input to store URL passed variable
<div style='position: absolute; top: 10px; left: 400px;'><input type='hidden' hidden='hidden' id='fromvs' name='fromvs' value="<?php echo $_SESSION['fromwhat']; ?>"></div>
4. But this thie field's value may lost after clicking button "srchvnd". So use a function to reset
$_SESSION['fromwhat'];
if (isset($_POST['srchvnd']))
{
$vs = $_POST['fromvs'];
somefunction($vs);
}
-----------------Source code----------------------
Segment in Calling html
....
<body>
<div style=" position: absolute; top: 1px; left: 5px; height:740px; width:205px; border-radius: 10px;" >
<!-- Start css3menu.com BODY section -->
<ul id="css3menu1" class="topmenu">
<li class="topfirst">Add a Subcontractor </li>
....
<li class="topmenu">Assign Subcontractor Contracts</li>
.....
<li class="toplast">Log Out</li>
</ul>
....
</div>
Segment in target php: VendorSearch.php
<?php
//VendorSearch.php
//http://mted202.mtaent.org:9051/ocr/login.php rweinbau
require_once('dbinfo.php');
session_start();
$c = oci_pconnect("ocr","ocrmta","HQT4");
oci_set_client_identifier($c, $_SESSION['username']);
$username = htmlentities($_SESSION['username'], ENT_QUOTES);
.....
$srchfor ="";
$fromwhat = $_GET['fromvs'];
$_SESSION['fromwhat'] = $fromwhat;
$vs = $fromwhat;
if (isset($_POST['srchvnd']))
{
$vs = $_POST['fromvs'];
somefunction($vs);
}
else
{
;
}
?>
<body>
<form class="vfrmsrch" name="vndsearch" id="vndsearch" action="VendorSearch.php?fromvs='<?php echo $fromwhat; ?>'" method="POST">
<div style='position: absolute; top: 10px; left: 400px;'><input type='hidden' hidden='hidden' id='fromvs' name='fromvs' value="<?php echo $_SESSION['fromwhat']; ?>"></div>
......
<td><input type="submit" class="slbt" name="srchvnd" id ="srchvnd" vaue="Search"></input></td>
......
</form>
.......
</body>
</html>
<?php
function somefunction($vvs){
//$msg = "We are inf somefunction() function </a></div><br>";
// echo "<div style='position: absolute; top: 100px; left: 10px;'><a style='color:blue'>".$msg;
$_SESSION['fromwhat'] = $vvs;
............
oci_close($c);
}

In menu (calling html) I call VendorSearch.php. variable fromvs is used in URL.
The target php VendorSearch.php will do different jobs based on the value of $_GET['fromvs']
In VendorSearch.php, aftersession_start(),
$srchfor ="";
$fromwhat = $_GET['fromvs'];
$_SESSION['fromwhat'] = $fromwhat;
$vs = $fromwhat;
Use hidden input to store URL passed variable
<div style='position: absolute; top: 10px; left: 400px;'><input type='hidden' hidden='hidden' id='fromvs' name='fromvs' value="<?php echo $_SESSION['fromwhat']; ?>"></div>
But this thie
Segment in Calling html
....
Add a Subcontractor
....
Assign Subcontractor Contracts
.....
Log Out
....
Segment in target php: VendorSearch.php
<?php
//VendorSearch.php
//http://mted202.mtaent.org:9051/ocr/login.php rweinbau
require_once('dbinfo.php');
session_start();
$c = oci_pconnect("ocr","ocrmta","HQT4");
oci_set_client_identifier($c, $_SESSION['username']);
$username = htmlentities($_SESSION['username'], ENT_QUOTES);
.....
$srchfor ="";
$fromwhat = $_GET['fromvs'];
$_SESSION['fromwhat'] = $fromwhat;
$vs = $fromwhat;
if (isset($_POST['srchvnd']))
{
$vs = $_POST['fromvs'];
somefunction($vs);
}
else
{
;
}
?>
<body>
<form class="vfrmsrch" name="vndsearch" id="vndsearch" action="VendorSearch.php?fromvs='<?php echo $fromwhat; ?>'" method="POST">
<div style='position: absolute; top: 10px; left: 400px;'><input type='hidden' hidden='hidden' id='fromvs' name='fromvs' value="<?php echo $_SESSION['fromwhat']; ?>"></div>
......
</form>
.......
</body>
</html>
<?php
function somefunction($vvs){
//$msg = "We are inf somefunction() function </a></div><br>";
// echo "<div style='position: absolute; top: 100px; left: 10px;'><a style='color:blue'>".$msg;
$_SESSION['fromwhat'] = $vvs;
............
oci_close($c);
}

My personal preference would be to specify the keys you wish to accept and be sure to run the value through htmlspecialchars().
$url_params = array(
'tab'
);
foreach( $url_params as $key ) {
echo !empty( $_GET[$key] ) ? '<input type="hidden" name="'. $key .'" value="'. htmlspecialchars( $_GET[$key] ) .'" />' : '';
}

Related

How can I remove this duplicate code in my code while still getting what I is needed

This first code below is the duplicate in my code :
php $con=mysqli_connect("localhost","root","","task");
$results = mysqli_query($con, "SELECT * FROM note");
while ($row = mysqli_fetch_array($results)) {
I want to remove it while I still can get the data that I want.
How can I be able to do it?
<?php $con=mysqli_connect("localhost","root","","task");
$results = mysqli_query($con, "SELECT * FROM note");
while ($row = mysqli_fetch_array($results)) {
$id = $row['id'];
echo '<button class="call_modal" style="cursor:pointer; width: 150px; height: 60px;">' .$row['title']. '</button>';
echo "<a href='update.php?id=$id'>edit</a>";
echo ' ';
echo "<a href='delete.php?id=$id'>delete</a>";
}
?>
<?php $results = mysqli_query($con, "SELECT * FROM note"); ?>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<div class="modal">
<div class="modal_close close"></div>
<div class="modal_main">
<div class="note">
<?php
echo '<br><br>';
echo '<div class="padding">'.$row['title'].'';
echo '<br><br><br><br>';
echo ''.$row['note'].'</div>';
echo '<br><br><br><br><br>';
echo '<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload File" name="submit">
</form>'
?>
<img src="x.png" class="close" style="line-height: 12px;
margin-top: 1px;
margin-right: 2px;
position:absolute;
top:0;
right:0;
width: 15px;
height:15px;">
</div>
</div>
<?php
}?>
check this out if this is true:
<?php $con=mysqli_connect("localhost","root","","task");
$results = mysqli_query("SELECT * FROM note");
$rows = mysqli_fetch_all($results, MYSQLI_ASSOC);
foreach ($rows as $row) {
$id = $row['id'];
echo '<button class="call_modal" style="cursor:pointer; width: 150px; height: 60px;">' .$row['title']. '</button>';
echo "<a href='update.php?id=$id'>edit</a>";
echo ' ';
echo "<a href='delete.php?id=$id'>delete</a>";
}
?>
<?php foreach ($rows as $row) { ?>
<div class="modal">
<div class="modal_close close"></div>
<div class="modal_main">
<div class="note">
<?php
echo '<br><br>';
echo '<div class="padding">'.$row['title'].'';
echo '<br><br><br><br>';
echo ''.$row['note'].'</div>';
echo '<br><br><br><br><br>';
echo '<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload File" name="submit">
</form>'
?>
<img src="x.png" class="close" style="line-height: 12px;
margin-top: 1px;
margin-right: 2px;
position:absolute;
top:0;
right:0;
width: 15px;
height:15px;">
</div>
</div>
<?php
}?>
If your goal is to not execute the same query twice you have to re-use the result. There are several ways to do that:
Reset the result
Example:
$results = mysqli_query("SELECT * FROM note");
while ($row = mysqli_fetch_array($results)) {
// do something
}
mysqli_data_seek($results, 0);
while ($row = mysqli_fetch_array($results)) {
// do something else
}
Why this is necessary: mysqli_fetch_array updates the internal pointer in $results that tells it what the next row is. When the first loop finishes, that internal pointer is set to beyond the last row, to indicate there are no more rows available. When your second loop starts, that pointer is still set there so it will not have any results to loop through. Using mysqli_data_seek you can manually set the pointer back to the beginning.
Fetch the results once
Example:
$results = mysqli_query("SELECT * FROM note");
$rows = mysqli_fetch_all($results, MYSQLI_ASSOC);
foreach ($rows as $row) {
// do something
}
foreach ($rows as $row) {
// do something else
}
Using mysqli_fetch_all will retrieve all rows as an array. You can then loop over that array as many times as you want. I'm explicitly asking for MYSQLI_ASSOC results, since you're using $row['id'] and $row['note']. mysqli_fetch_all() defaults to using MYSQLI_NUM results, which would not allow you to do that.
AFAIK, this is the most common approach, but it has a downside: you're retrieving all results into memory. If your query has a lot of results or if your application is already using a lot of memory, this may be a problem.
Since you said you're new to foreach, here's a short explanation of how it is different from other looping methods:
foreach ($rows as $index => $row) {
}
// is the same as:
for ($index = 0; $index < count($rows); $index++) {
$row = $rows[$index];
}
// or:
$index = 0;
while ($index < count($rows)) {
$row = $rows[$index];
}
// and if you're not interested in it, you don't need to ask for the $index:
foreach ($rows as $row) {
}
The main difference is that foreach also works easily on non-numeric arrays. For example:
foreach ($row as $column => $value) {
echo $column . ': ' . $value . '<br>';
// id: 123
// title: Note title
// note: Lorem ipsum ...
}

Keep Page Data on Refresh With $_POST

<!DOCTYPE html>
<html lang="en">
<head>
<h1>Table Generator</h1>
</head>
<body>
<center>Refresh</center>
<?php
$rows = (isset($_POST['rows']) ? $_POST['rows'] : null);
$cols = (isset($_POST['cols']) ? $_POST['cols'] : null);
$highlight = (isset($_POST['highlight']) ? $_POST['highlight'] : null);
if ($rows == "")
{
$rows = 10;
}
if ($cols == "")
{
$cols = 10;
}
if ($highlight == "")
{
$highlight = 5;
}
?>
<form method="post">
ROWS <input type="text" name="rows" value = "<?php echo $rows;?>" />
COLUMNS <input type="text" name="cols" value = "<?php echo $cols;?>" />
HIGHLIGHT <input type = "text" name = "highlight" value = "<?php echo $highlight;?>" /><br>
<input type="submit" value="Generate">
</form>
<?php
if(isset($_POST['rows']))
{
$randnumber = rand(0,100);
$rows = $_POST['rows'];
$cols = $_POST['cols'];
$highlight = $_POST['highlight'];
echo '<table border="1" align = "center">';
if (is_numeric($rows) and is_numeric($cols) and is_numeric($highlight))
{
if ($randnumber % 2 == 0)
{
echo '<center>The first number is <div class = "red">even</div></center>';
}
else
{
echo '<center>The first number is <div class = "green">odd</div></center>';
}
for($row = 1; $row <= $rows; $row++)
{
echo '<tr style = "background-color:green">';
for($col = 1; $col <= $cols; $col++)
{
if ($randnumber % $highlight == 0)
{
echo '<td style = "background-color: red">';
echo $randnumber;
$randnumber++;
echo '</td>';
}
else
{
echo '<td>';
echo $randnumber;
$randnumber++;
echo '</td>';
}
}
echo '</tr>';
}
echo '</table>';
}
else
{
echo "<center>Rows / Columns / Highlight must ALL be INTEGER values. Re-enter correct value(s).</center>";
}
echo '<pre><center>';
print_r($_POST);
echo '</center></pre>';
}
?>
<style type ="text/css">
h1 {
color: grey;
text-align:center;
}
form {
text-align: center;
padding-bottom: 20px;
}
a:link {
text-decoration: none;
}
.red {
color: red;
}
.green {
color: green;
}
</style>
</body>
</html>
So. I have this PHP code to generate a table based off the user's input and I recently ran into a problem I cant figure out how to fix.
It was working perfectly fine but now whenever I use the Refresh link it resets the entire page to default (i.e. default textbox values instead of keeping the current ones, removing the table).
So, I have 2 questions. How would I keep the data on refresh (with $_POST being used) and how to display the table with the default values when the page first loads.
Refresh
Clicking it will trigger browser's reload mechanism and you'll be asked to resubmit the form action, it will allow you to keep POST data.
You need to re-create the post if you want to keep the parameters. Can be done pretty eaily by looping thru the array.
<form method='POST' id='refresh' action='<?php echo $_SERVER['PHP_SELF']; ?>'>
<?php foreach($_POST as $k=>$v): ?>
<input type='hidden' name='<?php echo $k; ?>' value='<?php echo $v; ?>' />
<?php endforeach; ?>
<a href='#' onclick='document.getElementById("refresh").submit(); return false;'>refresh</a>
</form>
Note: This is a little longer than the other answer, but will not prompt to resend post data.

AJAX form sending data, PHP form not receiving it

I had this working earlier, but now it doesn't seem to want to pick up the data. It's possible something changed when I was trying to make it stop refreshing the page.
The form submits, but only for certain links. However the data gets sent across as normal. It's extremely strange.
This is the page the data is being sent to. Right now it just accepts the data and posts it for testing. "Text" shows but nothing else.
<?php
$ship_id = $_POST['transfer_ship'];
$char_id = $_POST['transfer_character'];
$pos_id = $_POST['transfer_position'];
$requested_by = $_POST['transfer_player'];
echo 'Success';
echo $ship_id;
echo $char_id;
echo $requested_by;
echo $pos_id;
echo $char_owner;
echo 'Text';
This is the form it's being sent from. It's part of a PHP UL series that's running. For the first result, the jQuery fires, I get the "Success" alert. For any of the other li links the data apparently gets sent (I use the F12 dev tools in Chrome, under Network, to see the header) but the page above either doesn't receive it or doesn't do anything with it.
jQuery:
<script type="text/javascript" src="../fancybox/jquery.fancybox.js?v=2.1.3"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".fancybox").fancybox();
});
</script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script>
// wait for the DOM to be loaded
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#transfer').ajaxForm(function() {
alert('Success!');
});
});
</script>
Form and UL:
<ul>
<?php
while(list($key, $val) = each ($arrayresult))
{
echo '<a href="#inline' .$val. '" class="fancybox"><li style="padding: 2px; margin: 0px; list-style: none;">';
echo '<img src="../images/profilepics/'.$charpic.'" style="float: right; padding-left: 10px; width: 40px;" />';
echo '<h2>'.$val.' Position</h2>';
echo '<p>Click here to apply for this position.</p>';
echo '</li></a>';
echo '<div id="inline' .$val. '" style="display:none;">';
echo '<h1>Request Character Transfer</h1>';
echo '<hr>';
echo '<form id="transfer" action="TransferRequest.php" method="post">';
echo '<label for="transfer_character">Character to Transfer</label>';
echo '<select id="transfer_character" name="transfer_character">';
echo '<option value="">Select Character</option>';
$request_character_query = "SELECT * FROM character_database WHERE character_active ='1' AND user_id = $user_id ORDER BY character_firstname DESC";
$request_character_result = mysqli_query($mysqli, $request_character_query);
/*** loop over the results ***/
foreach($request_character_result as $charrow)
{
/*** create the options ***/
echo '<option value="'.$charrow['character_id'].'">'. $charrow['character_firstname'] . " " . $charrow['character_surname'] . '</option>'."\n";
}
echo '</select>';
echo '<p>Applying for the '.$val.' position on the '.$shipname.'</p>';
echo '<p>If this is correct, please submit below</p>';
echo '<input type="hidden" value="'.$val.'" name="transfer_position">';
echo '<input type="hidden" value="'.$ship_id.'" name="transfer_ship">';
echo '<input type="hidden" value="'.$user_id.'" name="transfer_player">';
echo '<input value="Submit Request" type="submit" class="styled">';
echo '</form>';
echo '</div>';
}
?>
</ul>
I figured it out! I have my htaccess file removing the .php extension, but I had .php on the redirect link for ajax. So it was hitting the .php page then redirecting WITHOUT the POST data.

Assigning a value to a PHP global variable to alert

I am working on a very basic random name generator. The generator works great, and is called by an HTML form submit button. Now, in the case that a user wanted to save the name, I will have a second button that will call a PHP mail action to email the name. Before I add the mail function, I'm just trying to store the variable somewhere so that I can alert it and validate that I have control over it. In the following code $field2 is the name which is located by $id_num which equals $search_str. I then try and assign $field2 to the global variable $nameContainer:
<body>
<?
$nameContainer = "Mary";
?>
<?
function loadName() {
global $nameContainer;
if(!empty($_POST['act'])) {
$lineNum = rand(1, 5189);
$search_str = $lineNum;
$lines = file('names_girls_5189_origin.csv');
foreach($lines as $line){
list($id_num, $field2, $field3, $field4)=explode(",",$line);
$nameContainer = ($id_num == $search_str) ? "$field2" : "";
echo ($id_num == $search_str) ?
"<table style= 'height: 100%;'>
<tr style='width: 100%; height= '200px';'>
</tr>
<center><span class='myText' style='color: white; font-size: 48px;'>$field2</span>
<span style='color: #E8C8D5; font-size: 36px'>Smith</span><br/>
<span class='myText' style='color: #2E7B4D; font-size: 24px;'>Origin: $field3</span><br/>
<span class='myText' style='color: #2E7B4D; font-size: 24px;'>Meaning: $field4</span></center>
</table>" : "";
}
}
}
loadName();
?>
<script type="text/javascript">
function alertName() {
alert("<? getName(); ?>");
}
</script>
<?
function getName() {
global $nameContainer;
echo $nameContainer;
}
?>
<center><form action="index.php" method="post">
<input type="hidden" name="act" value="run" />
<p><input type="submit" value="New" /></p>
</form>
</center>
<center><button onclick="alertName()">Alert</button></center>
</body>
It appears my problem stems from $nameContainer = ($id_num == $search_str) ? "$field2" : ""; because $nameContainer = $field2; works but assigns the very last name in the csv rather than the one that matches the search string. I realize there's probably some basic logic I'm missing here, so any help is appreciated!
Update (sample csv):
ID,Name,Origin,Meaning
1,Aaliyah,"Arabic, Hebrew","high exalted, to ascend"
2,Akala,Aboriginal,A parrot.
3,Alba,Aboriginal,A sand hill. Also see Albina.
5188,Zelma,,A divine helmet. From the name Anselma. Also see Salima.
5189,Zola,,Life.`
I think, you need to check if $nameContainer has content and break the loop:
$nameContainer = ($id_num == $search_str) ? "$field2" : "";
if(!empty($nameContainer)){
break;
}
But, to make it work, you need to initialize $nameContainer with empty string:
$nameContainer = "";
It seems to me you're using $search_str to pick a line (an element of the $lines array) at random. You should use array_rand for this:
function loadName() {
global $nameContainer;
if(!empty($_POST['act'])) {
list($id_num, $field2, $field3, $field4)=explode(",",array_rand(file('names_girls_5189_origin.csv')));
$nameContainer = $field2;
echo "<table style= 'height: 100%;'>...</table>" : "";
}
}

PHP Value of Variable is undefined

I am getting " Notice: Undefined index:k" in the PHP code. K is the name of the text field and I am using $_GET[] method to get the value of k. In the below mentioned example I am trying to keep the value available even after the form is submitted. This Code runs fine for the first time but the second time it gives the above error.
<form name="keywordquery" method="get" action="keywordsearch.php">
<fieldset class="fieldsetclass"><legend class="legendclass">Search by
Keywords</legend>
<div id="searchbox">
<input type="text" name="k" value="<?php if(isset($_GET['k'])){echo
htmlentities($_GET['k']);} ?>" style="border: 1px, thin; width:92%; "/> <input
type="image" style="margin-bottom: 0; margin-top: 2px;" src="search.png"
value="submit" />
</div>
</fieldset>
</form>
</div>
<table id="dataTable" cellpadding="0" cellspacing="0" border="1" style="border-
radius:20px; box-shadow: 9px 5px 8px #7E9044;">
<tbody>
<?php
// PAGINATION Code. check if the starting row variable was passed in the
URL or not
if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
//we give the value of the starting row to 0 because nothing was found in URL
$startrow = 0;
//otherwise we take the value from the URL
} else {
$startrow = (int)$_GET['startrow'];
}
$k1 = $_GET['k'];
$term = explode(" ", $k1);
$query = "SELECT * FROM data ";
foreach ($term as $each) {
$i++;
if($i==1)
{
$query .= "WHERE keywords LIKE '%$each%' ";
}
else {
$query .= " OR WHERE keywords LIKE '%$each%' ";
}
}
$query .= "LIMIT $startrow, 1";
$connection = mysql_connect("xxxx", "xxxxx","");
if(!$connection)
echo "No database connected";
$dbase = mysql_select_db("xxxxxxxx", $connection);
if(!$dbase)
echo "No datatable connected";
$ourquery1 = mysql_query ($query);
if(!$ourquery1)
echo "No query found";
$row1 = mysql_num_rows ($ourquery1);
if ($row1 > 0)
{
while($result = mysql_fetch_assoc($ourquery1))
{
echo "<tr>";
$title = $result['title'];
$link = $result['link'];
$region = $result['region'];
$sector = $result['sector'];
$theme = $result['theme'];
echo "<td> <a href=$link><h3>$title<h3></a>";
echo "<h4>Sector: $sector
Theme: $theme
<br> Region: $region </td>";
}
}
echo "</tbody>";
echo 'Next';
echo 'Prev';
Replace the line:
$k1 = $_GET['k'];
with something like:
$k1 = isset($_GET['k'])? $_GET['k'] : $default_k_value;
You don't show the complete form so it is tough to tell what is wrong but here is a hint. Swap $_GET with $_REQUEST.
Example:
<?php if(isset($_REQUEST['k'])){echo
htmlentities($_REQUEST['k']);} ?>
If the form is using a POST method, the value would be in $_POST. If the form uses a GET method, the value would be in $_GET. However $_REQUEST will contain the form fields whether the form used POST or GET.

Categories