Page 1 of 1

[Solved] Passing text not numeric values problem

Posted: Thu Aug 18, 2005 5:32 pm
by Addos
When I run this code:

Code: Select all

<?PHP echo "<select name='months' id='months'>\n
	  <option value=\"'%'\">Select</option>"; 
		while($dbRow = mysql_fetch_array($GetMonths)){ 
  		echo "<option value='"
		. $dbRow["months_idpk"]  
		. "'>"
		. $dbRow["name"]
		."</option>\n"; 
		} echo "</select>\n"; 
		?>
I get as expected in the browser
January
February
March

I’m really stuck though as I want to insert into my database one of the three options i.e. January February March but what I’m getting inserted into my data base at the moment is the months_idpk id i.e. the numeric values 1, 2 or 3.

I’m using this to insert my data and have tired a few variations on it but I still get the same numeric values inserted. Can this be done or do I need to run another query before I make the final insert?


Code: Select all

$insertSQL = sprintf("INSERT INTO enquiries (months) VALUES (%s )",

                       GetSQLValueString($_POST['months'], "text"),
Tried also same result

Code: Select all

GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($dbRow["name"], "text"),
Thanks a mil
B

Posted: Thu Aug 18, 2005 5:34 pm
by feyd
you're getting the primary key value, which you store as the "value" attribute for each option. Replace that element with your text element.

Posted: Thu Aug 18, 2005 5:44 pm
by Addos
Thanks for this. I think I need some rest now :oops:

B