473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

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>";
}
</SELECT>
<input '.$addnewq.' type="text" name="questtxt" value"'.$questtxt.'"/>';
?>[/php]Help would be much appreciated!!!
Apr 10 '08 #1
1 2921
ronverdonk
4,258 Expert 4TB
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.

MODERATOR
Apr 10 '08 #2

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

Similar topics

2
by: Krista | last post by:
Hi, can i load the same table in the two drop-down list? $DBName = Krista; $Query = "select * from Parts"; $ResultPart0 = mysql_db_query($DBName, $QueryPart, $linkID); $ResultPart1 =...
13
by: Leszek Taratuta | last post by:
Hello, I have several drop-down lists on my ASP.NET page. I need to keep data sources of these lists in Session State. What would be the most effective method to serialize this kind of data...
1
by: pmelanso | last post by:
Hello, I have a drop down list which is dynatically loaded from a database and I have a second drop down list that is also dynatically loaded depending on what is selected in the first drop down...
1
by: Jeff Gardner | last post by:
Greetings: I have a table with 3 pieces of data that I would like to use to dynamically populate 3 drop downs using javascript. The fields are state, orgname, office. If it's not already...
2
by: cpptutor2000 | last post by:
Could some PHP guru please help me? I am creating a dynamic dropdown list using a code snippet(Section A) as below: Section A: $sql_query=mysql_query("SELECT DISTINCT semester, year from...
0
by: mjohnson0321 | last post by:
I am trying to incorporate a CSS drop-down menu into a site (suckerfish menu). The menu gets lost behind the content below it, but only on one of the drop downs (News). The error occurs on all of...
8
by: stekk | last post by:
Question: How do I display/echo the values in page the selected values from drop down lists in page 2? I think this is the line that I have to add some code to make the values SELECTED. Any help is...
1
by: jej1216 | last post by:
Background: I have an PHP form that inserts data into a MySQL DB, and it works. Severity of Incident: <select name="severity" size="1"> <option value="">Select a Severity Option</option>...
11
by: tokcy | last post by:
Hi everyone, I am new in php and ajax, i am facing the prob while i click on element of first drop down then in second dropdown all element showl come from database. I mean i have three dropdown 1....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.