Please see my code below
I have a select box populated by table names from a MySQL database. I chose a table from the dropdown list and that table name is displayed. I then click the Get Records button and the table name in the select box reverts to its previous value. If I then click the Next record button the table name is displayed correctly in the drop down select box. Can anyone suggest what I have wrong in my code that means the wrong name is displayed in the select box. I have been at this for a couple of hours and can’t spot it.
TIA
[php]
<?php $query="SELECT tbl_name,opt_name FROM tables"; $result = mysql_query ($query); echo ""; while ($temp = mysql_fetch_assoc($result)) { if ($temp['tbl_name'] == $_SESSION['rec_table']){ echo "".htmlentities($temp['opt_name']).""; } else { echo "".htmlentities($temp['opt_name']).""; } } echo ""; ?> <!--Choose starting record-->
<label class="cs1">Select first record number:</label>
<input type="text" name="rec_from" value="1" size="6" >
<input id="get_records" type="submit" name="get_records" value="Get Records"/><br />
<input style="margin:5px 0 5px 10px" name="next_rec" id="next_rec" type="submit" value="Next Record" />
<input style="margin:5px 0 5px 90px" name="new_rec" type="submit" value="Create New Master Person" >
</form>
<?php
// Display records in table
if (isset($_POST[‘get_records’]) || isset($_POST[‘next_rec’]))
{
if (isset($_POST[‘get_records’])){
$table = ($_POST[‘source’]);
$table = mysql_real_escape_string($table);
$new_persona[‘rec_table’]=$table;
$_SESSION[‘rec_table’] = $table;
$record = ($_POST[‘rec_from’]);
$record = mysql_real_escape_string($record);
$record = $record - 1;
$_SESSION[‘last_rec’] = $record;
}
if (isset($_POST['next_rec'])){
$last_rec = $_SESSION['last_rec'];
$record = $last_rec + 1;
$table = mysql_real_escape_string ($_SESSION['rec_table']);
$_SESSION['last_rec'] = $record;}
Code continues here with other bits that aren’t relevant to the problem.
[/php]
Colin