By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,137 Members | 1,981 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,137 IT Pros & Developers. It's quick & easy.

Drop down list/mysql_fetch_array() problem: Why does the data repeat on page reload.

P: 1
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_array() 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_array is called using mysql_free_result($question_set); the second time but it hasn't work.

Drop down list code:[php]<?php
echo'<SELECT name="question" id="question">
<OPTION value="" style="COLOR:#ff0000;BACKGROUND-COLOR:#FFCC00;">Add New</OPTION>';
$question_set = get_all_questions_by_proj_id();
while ($question = mysql_fetch_array($question_set))
echo '<option value="'. $question["qu_id"] . '" ';
if ((isset($_POST['resetans']))&&($question["qu_id"] == $_POST['question']))
echo ' selected="selected"';
echo">". $question["question"] ."</option>";
<input '.$addnewq.' type="text" name="questtxt" value"'.$questtxt.'"/>';
?>[/php]Help would be much appreciated!!!
Apr 10 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 4,258
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

Apr 10 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.