Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-04-2010, 11:42 AM   PM User | #1
wookiwar
New to the CF scene

 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
wookiwar is an unknown quantity at this point
Contact form problem - option numeric values in email not text

Hi
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

cheers
wookiwar is offline   Reply With Quote
Old 02-04-2010, 11:45 AM   PM User | #2
SKDevelopment
Regular Coder

 
Join Date: Mar 2006
Posts: 238
Thanks: 3
Thanked 37 Times in 37 Posts
SKDevelopment has a little shameless behaviour in the past
By setting the values to strings, not to numbers e.g. like this:
Code:
<option value="">---</option>
<option value="Google">Google</option>
<option value="Yahoo">Yahoo</option>
If I have not understood the problem correctly, please ask questions.
__________________
PHP Programmer

Last edited by SKDevelopment; 02-04-2010 at 11:48 AM..
SKDevelopment is offline   Reply With Quote
Old 02-04-2010, 11:50 AM   PM User | #3
wookiwar
New to the CF scene

 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
wookiwar is an unknown quantity at this point
Thanks however the numbers are required to post to the database

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

thanks
wookiwar is offline   Reply With Quote
Old 02-04-2010, 11:57 AM   PM User | #4
SKDevelopment
Regular Coder

 
Join Date: Mar 2006
Posts: 238
Thanks: 3
Thanked 37 Times in 37 Posts
SKDevelopment has a little shameless behaviour in the past
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 ...
__________________
PHP Programmer
SKDevelopment is offline   Reply With Quote
Old 02-04-2010, 12:32 PM   PM User | #5
wookiwar
New to the CF scene

 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
wookiwar is an unknown quantity at this point
Here is the Mysql table info
[CODE]CREATE TABLE `referredby` (
`referred_by_id` INTEGER(11) NOT NULL AUTO_INCREMENT,
`referred_by_name` VARCHAR(30) COLLATE latin1_swedish_ci DEFAULT NULL,
PRIMARY KEY (`referred_by_id`)
)ENGINE=InnoDB
AUTO_INCREMENT=9 CHARACTER SET 'latin1' COLLATE 'latin1_swedish_ci';
[CODE]

CONTACT Form field

[CODE]
<select name="referred_by_id" id="referred_by_id">

<?php

do {
?>
<option value="<?php echo $row_WADADynListreferredby['referred_by_id']?>"><?php echo $row_WADADynListreferredby['referred_by_name']?></option>
<?php
} 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);
}
?>
</select>
[CODE]

thankyou page
[CODE]
<tr>
<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>
</tr>[CODE]

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
wookiwar is offline   Reply With Quote
Old 02-04-2010, 01:02 PM   PM User | #6
SKDevelopment
Regular Coder

 
Join Date: Mar 2006
Posts: 238
Thanks: 3
Thanked 37 Times in 37 Posts
SKDevelopment has a little shameless behaviour in the past
At the thank you page you could extract the search engine name with code like this (not checked):
PHP Code:
<?php
// 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.
__________________
PHP Programmer
SKDevelopment is offline   Reply With Quote
Old 02-04-2010, 01:36 PM   PM User | #7
wookiwar
New to the CF scene

 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
wookiwar is an unknown quantity at this point
Smile Thank you --

As always help is at hand when you ask.
thank you so much

Stuart
wookiwar is offline   Reply With Quote
Reply

Bookmarks

Tags
php sql conatc form

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:48 AM.


Advertisement
Log in to turn off these ads.