Hey all !
I just created a dropdown list with value coming from my DB, and it writes the selected value to the DB, which is what I want. However, when I reload the page the dropbox is "resetted", and I don't know how to make it understand that there's a value selected.
Hope you understand my problem, if not I'll give you more details
Thx !
Dropdown writing to DB, but not reading
Started by blink41, Apr 28 2010 06:38 AM
9 replies to this topic
#1
Posted 28 April 2010 - 06:38 AM
|
|
|
#2
Posted 28 April 2010 - 06:41 AM
When you reload your page by refreshing it (F5) or by opening the same link again?
You can set a default value for the dropdown list, if that's what bothering you.
You can set a default value for the dropdown list, if that's what bothering you.
// d-_-b+
#3
Posted 28 April 2010 - 06:48 AM
It's a form. When I click on "send" it writes the selected value to the DB, and I come back to the page, which is normal. I'd like it to know that I've selected a value in the dropdown list. In fact the default value is nothing. Do you want a screenshot ?
#4
Posted 28 April 2010 - 07:00 AM
I think i understand what you mean, but why do you want the selected value on the dropdown list if you already selected and stored it in the database?
// d-_-b+
#5
Posted 28 April 2010 - 09:22 AM
The form I'm writing is in fact a form to modify a product, and I'll use it as a product catalog (people will open it if they want all the details of the products). If they want to modify a product, I don't want them to select the value everytime, and if it's someone different that want to modify the product, it's way better for this person to know what the original product was.
#6
Posted 28 April 2010 - 09:28 AM
Well, you can always get the value from the database, and then display it into the dropdown list, yes?
// d-_-b+
#7
Posted 28 April 2010 - 11:58 PM
Here are some screenshots, I think they are better than words.
The file whatiwant represents a selection i make. When I click on submits, the screenshot whatiget represents what I have : the radiobutton value is ok, the dropdown is not. The screenshot dbforme shows the table I take the values from. When I change the radiobutton, another dropdown list shows, and then I select the value.
If I read the value from the database I'm afraid that :
1st : there will be a duplicate entry in the dropdown list
2nd : the value written in the table will show in both of the dropdown lists.
I don't know if you see what I mean, I suck at explaining...
Anyway, thanks for your time, I really appreciate it !
EDIT: Here is a sample of the code I'm using :
The file whatiwant represents a selection i make. When I click on submits, the screenshot whatiget represents what I have : the radiobutton value is ok, the dropdown is not. The screenshot dbforme shows the table I take the values from. When I change the radiobutton, another dropdown list shows, and then I select the value.
If I read the value from the database I'm afraid that :
1st : there will be a duplicate entry in the dropdown list
2nd : the value written in the table will show in both of the dropdown lists.
I don't know if you see what I mean, I suck at explaining...
Anyway, thanks for your time, I really appreciate it !
EDIT: Here is a sample of the code I'm using :
<select name="formeProduit2" id="formeProduit2" <?php echo($formetype2); ?> size="1" \>
<?php
// insertion des constantes liées à la base de données
include("connect_db.inc");
// Connection au serveur MySql et à la bdd
$ConnexionServeur = mysql_connect($mysql_hostname, $mysql_username, $mysql_userpwd);
$ConnexionBdd = mysql_select_db($mysql_basename, $ConnexionServeur);
//
// PHP DYNAMIC DROP-DOWN BOX - HTML SELECT
//
// 2006-05, 2008-09, 2009-04 http://kimbriggs.com/computers/
//
// Function creates a drop-down box
// by dynamically querying ID-Name pair from a lookup table.
//
// Parameters:
// intIdField = Integer "ID" field of table, usually the primary key.
// strMethod = Sort as asc=ascending (default) or desc for descending.
// strNameField = Name field that user picks as a value.
// strNameOrdinal = For multiple drop-downs to same table on same page (Ex: strNameField.$i)
// strOrderField = Which field you want results sorted by.
// strTableName = Name of MySQL table containing intIDField and strNameField.
//
// Returns:
// HTML Drop-Down Box Mark-up Code
//
$strQuery = "SELECT tricot FROM forme, produit WHERE forme.tricot=produit.forme";
$rsrcResult = mysql_query(strQuery);
$row = mysql_fetch_array($rsrcResult);
$strC = $row['tricot'];
// $strD = $arrayRowInit["forme.tricot"];
echo "<option selected='selected'>$strC</option>";
//echo "<option selected='selected'></option>";
mysql_close($ConnexionServeur);
?>
Attached Files
Edited by blink41, 29 April 2010 - 02:04 AM.
added part of the code
#8
Posted 29 April 2010 - 04:29 AM
Okay it works, I still have to make a better SQL query. I spent all the morning on that thing, and I just realised I had forgotten a $...
$rsrcResult = mysql_query($strQuery);
$rsrcResult = mysql_query($strQuery);
#9
Posted 29 April 2010 - 04:52 AM
So you get what you want now?
And please, change connect_db.inc to .php or something, cause *.inc is readable from the world. Try open db_connect.inc in your web browser.
And please, change connect_db.inc to .php or something, cause *.inc is readable from the world. Try open db_connect.inc in your web browser.
// d-_-b+
#10
Posted 29 April 2010 - 05:24 AM
Yes I barely get what I want ksemeks, I still have to deal with the duplicate entry in the dropdown though.
I just tried opening connect_db.inc. Indeed, it's just not secured at all ! It was an example from my teacher's course, I think I'll warn him about that, thanks for the tip !
I just tried opening connect_db.inc. Indeed, it's just not secured at all ! It was an example from my teacher's course, I think I'll warn him about that, thanks for the tip !


Sign In
Create Account


Back to top










