SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2008
    Location
    Dublin, Ireland.
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    capturing value sent in dropdown list in form

    Really would appreciate any help on this.

    <tr><td class="span">Referred by<span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td></tr>
    <?php
    if(isset($_POST['referee'])&&$_POST['referee']!=="")
    {
    $select=$_POST['referee'];
    ` }
    else
    {
    $select = "";
    }
    ?>
    <tr><td class="input">
    <select name="referee">
    <?php $list=mysql_query("SELECT * FROM referee order by id asc");
    while($row_list = mysql_fetch_array($list, $connection))
    { ?>
    <option value="<?php echo $row_list['position'];?>"<?php if($row_list['position'] == $select){ echo " selected";}?>><?php echo $row_list['name']; ?></option><?php } ?>

    </select>
    </td></tr>

    I'm getting 'unexpected T_ENCAPSED_AND_WHITESPACE' error.

    I have a database with a table named 'referee' and three fields - id, name, position.

    I am just trying to catch the value returned when the user selects an item from the list (Seminar, Advert, Website).

    My head is done in from wrangling with it.

    Thanks.....derm_w.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    The closing brace for the first if statement has a rogue quote (called a backtick) at the start of the line, that needs to be removed.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2008
    Location
    Dublin, Ireland.
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks pmw57.

    I'd never have seen that sucker.

    I'm getting an empty list now in the drop down but at least I can see the form to work on.

    I'm trying to have three items display in the drop down ( Seminars, Adverts, Website) and when the user selects one and submits the form I want to catch the item they have selected. I can catch the email, name, phone and message all right, but the drop down is another thing altogether.

    If anyone can point me in the right direction it'd be mightily appreciated.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    To help with debugging you can use var_dump($_POST) to see all that was posted.

    Instead of checking isset and !== "", it can be more effective to just check if it's not empty instead

    Code php:
    if (!empty($_POST['referee'])) {
     
    }

    When assigning a value from $_POST, you shouldn't blindly accept what comes from there because naughty people can load it up with whatever they desire. Use filter_input to sanitize the input. Here's a list of sanitize filters

    Code php:
    $select = filter_input(INPUT_POST, 'search', FILTER_SANITIZE_SPECIAL_CHARS);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2008
    Location
    Dublin, Ireland.
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again pmw57 for that good info.

    I look forward to another crack at it later today.


Bookmarks

Posting Permissions

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