PHP Value of Variable is undefined -
PHP Value of Variable is undefined -
i getting " notice: undefined index:k" in php code. k name of text field , using $_get[] method value of k. in below mentioned illustration trying maintain value available after form submitted. code runs fine first time sec time gives above error.
<form name="keywordquery" method="get" action="keywordsearch.php"> <fieldset class="fieldsetclass"><legend class="legendclass">search 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 starting row variable passed in url or not if (!isset($_get['startrow']) or !is_numeric($_get['startrow'])) { //we give value of starting row 0 because nil found in url $startrow = 0; //otherwise take value url } else { $startrow = (int)$_get['startrow']; } $k1 = $_get['k']; $term = explode(" ", $k1); $query = "select * info "; foreach ($term $each) { $i++; if($i==1) { $query .= "where keywords '%$each%' "; } else { $query .= " or keywords '%$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 '<a href="'.$_server['php_self'].'?startrow='.($startrow+1).'">next</a>'; echo '<a href="'.$_server['php_self'].'?startrow='.($startrow-1).'">prev</a>';
replace line: $k1 = $_get['k'];
with like: $k1 = isset($_get['k'])? $_get['k'] : $default_k_value;
php
Comments
Post a Comment