[Solved] Passing text not numeric values problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

[Solved] Passing text not numeric values problem

Post 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
Last edited by Addos on Thu Aug 18, 2005 5:45 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Post by Addos »

Thanks for this. I think I need some rest now :oops:

B
Post Reply