I have a form where the user chooses an item from the dropdown(Term) which then displays data(Rate) from the database. The user should be able to choose different terms to get the results however when you hit submit it works the first two times and then loses the data the third time. Also, when you first enter the page it has a specific Term(cid=1) that should be displayed. Does anyone know why it is losing the data?
Code:<?php $calledforthefirsttime = true; ?> <?php if ($calledforthefirsttime == true) { $id = $_GET[id']; $sql = "SELECT * FROM table1 ORDER BY Display"; $result = mysql_query($sql, $db) ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <select name="cid" id="cid"> <?php while ($row=mysql_fetch_array($result)) { if ($cid == $row[cid]) { echo "<option value=\"$row[cid]\" selected>$row[Term]\n"; } else { echo "<option value=\"$row[cid]\">$row[Term]"; } } echo "</select> </select> <input type=hidden name=id value=$id> <input type='submit' name='button' id='button' value='Submit'> "; ?> </form> <?php $cid = 1; $sql3 = "SELECT * FROM table2 WHERE cid = '$cid' AND id='$id'"; $result3 = mysql_query($sql3, $db); $row3 = mysql_fetch_assoc($result3); $cid = $_POST['cid']; $id = $_POST['id']; echo "Pricing 1: $row3[rate]"; } ?> <?php if ((isset($_POST['cid'])) && ($cid!="")) { $cid = $_POST['cid']; $calledforthefirsttime = false; $id = $_POST['id']; $sqlp="SELECT * FROM table2 WHERE cid = '$cid' AND id='$id'"; $resultp = mysql_query($sqlp, $db); while ($rowp = mysql_fetch_array ($resultp)) { echo "Pricing: $rowp[rate]"; } } ?>



Reply With Quote

Bookmarks