View Full Version : Contact form problem - option numeric values in email not text

02-04-2010, 12:42 PM
I have a contact form which posts the data via PHP MySql to a data base then redirects to a second page and reads the form then send the data via an email to admin.

Problem is when form values are read on second page some Fields are SELECT dropdowns on the form and it is passing the value number and not the text value.

ie Form has this code
[CODE]<option value="1">---</option>
<option value="2">Google</option>
<option value="3">Yahoo</option>[CODE]

on the second page I get the value "2" instead of "Google" in the passed form value.

How can I simply get "google instaed of the Numeric value

PS the Drop down Select option is populated from an SQL table


02-04-2010, 12:45 PM
By setting the values to strings, not to numbers e.g. like this:

<option value="">---</option>
<option value="Google">Google</option>
<option value="Yahoo">Yahoo</option>

If I have not understood the problem correctly, please ask questions.

02-04-2010, 12:50 PM
Thanks however
The database is set up to receive numeric values
If I change to text as you suggest this wont work with the Database tables
and I would have to recode other pages also.
any other ideas would be helpful


02-04-2010, 12:57 PM
What your database table contains ? Numeric index and name of the search engine ? Then at the resulting page you could extract the search engine name by received number with a simple SELECT query.

Could you give a little bit more details about your system please ?

It is OK to send numbers if this is necessary. It is only necessary to get names by numbers at the resulting page ...

02-04-2010, 01:32 PM
Here is the Mysql table info
[CODE]CREATE TABLE `referredby` (
`referred_by_name` VARCHAR(30) COLLATE latin1_swedish_ci DEFAULT NULL,
PRIMARY KEY (`referred_by_id`)
AUTO_INCREMENT=9 CHARACTER SET 'latin1' COLLATE 'latin1_swedish_ci';

CONTACT Form field

<select name="referred_by_id" id="referred_by_id">


do {
<option value="<?php echo $row_WADADynListreferredby['referred_by_id']?>"><?php echo $row_WADADynListreferredby['referred_by_name']?></option>
} while ($row_WADADynListreferredby = mysql_fetch_assoc($WADADynListreferredby));
$rows = mysql_num_rows($WADADynListreferredby);
if($rows > 0) {
mysql_data_seek($WADADynListreferredby, 0);
$row_WADADynListreferredby = mysql_fetch_assoc($WADADynListreferredby);

thankyou page
<th >How you found us:</th>
<td ><input type="text" name="referred_by_id" id="referred_by_id" value="<?php echo $_POST["referred_by_id"]; ?>" size="32" /></td>

System Is MySQL on Apache server with PHP5

I think I'm starting to see the solution....
I create a select statment in the second page using the ID number from the form data to read the "google" etc from the database.
that makes sense I need help making the code

thank you

02-04-2010, 02:02 PM
At the thank you page you could extract the search engine name with code like this (not checked):

// do not remove intval() - here it is against SQL injections!!!
$referred_by_id = intval($_POST["referred_by_id"]);
$query = "SELECT referred_by_name FROM referredby WHERE referred_by_id=$referred_by_id";
$res = mysql_query($query);
$row = mysql_fetch_assoc($res);
$referred_by_name = (false!==$row)?$row['referred_by_name']:'';

I supposed here that your DB is MySQL and that you are using mysql_* functions (not e.g. mysqli_* functions or PDO) to work with it. Otherwise the code would be different of course but I think it could give you an idea anyway.

I mean you could extract the search engine name by number from the DB (please be careful not to use the posted data directly in the query to avoid SQL injection attacks) and then use it in the code as you see fit.

02-04-2010, 02:36 PM
As always help is at hand when you ask.
thank you so much