Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    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.
    Last edited by SKDevelopment; 02-04-2010 at 11:48 AM.

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    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 ...

  • #5
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    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.

  • #7
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Thank you --

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

    Stuart


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •