Sorry about the title its a tricky one.
I have a form which allows me to add a question and answers into a mysql database via a combination of, if a certain option is chosen and the reset button is pressed then a text box appears to enter a new question or answer or both. the newly entered data is then inserted into mysql. The newly entered data is then requested by mysql_fetch_arr ay() to be displayed as options in the drop down list.
If i then select the newly entered options in the drop down list they are then checked in the database to see if they already exist and if they do the insert statement is bypassed and the primary key captured and used else where, this does work. But for some reason when the page reloads even tho the data only appears once in the mysql table it appears twice as an option in the drop down list. Its is also the same if i do the process again the data is entered in the list a third time. Yet the primary key which is held as the value of the option is the same for all instances.
I have tried clearing the memory before the mysql_fetch_arr ay is called using mysql_free_resu lt($question_se t); the second time but it hasn't work.
Drop down list code:[php]<?php
echo'<SELECT name="question" id="question">
<OPTION value="" style="COLOR:#f f0000;BACKGROUN D-COLOR:#FFCC00;" >Add New</OPTION>';
$question_set = get_all_questio ns_by_proj_id() ;
while ($question = mysql_fetch_arr ay($question_se t))
{
echo '<option value="'. $question["qu_id"] . '" ';
if ((isset($_POST['resetans']))&&($question["qu_id"] == $_POST['question']))
{
echo ' selected="selec ted"';
}
echo">". $question["question"] ."</option>";
}
</SELECT>
<input '.$addnewq.' type="text" name="questtxt" value"'.$questt xt.'"/>';
?>[/php]Help would be much appreciated!!!
I have a form which allows me to add a question and answers into a mysql database via a combination of, if a certain option is chosen and the reset button is pressed then a text box appears to enter a new question or answer or both. the newly entered data is then inserted into mysql. The newly entered data is then requested by mysql_fetch_arr ay() to be displayed as options in the drop down list.
If i then select the newly entered options in the drop down list they are then checked in the database to see if they already exist and if they do the insert statement is bypassed and the primary key captured and used else where, this does work. But for some reason when the page reloads even tho the data only appears once in the mysql table it appears twice as an option in the drop down list. Its is also the same if i do the process again the data is entered in the list a third time. Yet the primary key which is held as the value of the option is the same for all instances.
I have tried clearing the memory before the mysql_fetch_arr ay is called using mysql_free_resu lt($question_se t); the second time but it hasn't work.
Drop down list code:[php]<?php
echo'<SELECT name="question" id="question">
<OPTION value="" style="COLOR:#f f0000;BACKGROUN D-COLOR:#FFCC00;" >Add New</OPTION>';
$question_set = get_all_questio ns_by_proj_id() ;
while ($question = mysql_fetch_arr ay($question_se t))
{
echo '<option value="'. $question["qu_id"] . '" ';
if ((isset($_POST['resetans']))&&($question["qu_id"] == $_POST['question']))
{
echo ' selected="selec ted"';
}
echo">". $question["question"] ."</option>";
}
</SELECT>
<input '.$addnewq.' type="text" name="questtxt" value"'.$questt xt.'"/>';
?>[/php]Help would be much appreciated!!!
Comment