SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,383
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    db driven radio button

    I want to modify a select box as a radio button for my CMS that allows the user to select "Future", "Past", or "All" for a list of workshops by start dates. the code for the select box is:
    PHP Code:
    <?php
    <select name ="visible" id="visible">
    <?
    php 
    if ($visible == 'Y' ){
    echo 
    "<option selected='selected' value='Y' >Yes</option>\n
    <option value='N' >No</option>\n"
    ;
    }else{
    //if visible is set to N
    echo "<option selected='selected' value='N' >No</option>\n
    <option value='Y' >Yes</option>\n"
    ;
    }
    ?>
    </select>
    </p>
    I know I need to start with:
    PHP Code:
    <?php
     
    <input type="radio" name="show" id="showF" value="F" checked /> Future<br />
     <
    input type="radio" name="show" id="showP" value="P" /> Past<br />
     <
    input type="radio" name="show" id="showA" value="A" /> All<br />
    What's next?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Write the code that accepts and elaborates the new form field value?

  3. #3
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,383
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes. what would the code be?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    It should be similar to the code you have for the select box, as both send one value to the receiving script.
    $_POST['show'] (or $_GET['show'] depending on the form method) contains the form field value.

  5. #5
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,383
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    4 It should be similar to the code you have for the select box,
    Yes, but "similar" doesn't do it for me. I've been searching for the specific code and cannot find a relevant example. Can you provide, or point me to a specific example?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    http://www.homeandlearn.co.uk/php/php4p10.html
    The first result of a 'php radio button' google search

  7. #7
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,383
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aha! I've just been searching on "xhtml radio button."
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  8. #8
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,383
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I have the radio button code right, but the insert query is producing the error message:
    Error updating program category: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'show='F' WHERE id='33'' at line 9
    I have echoed the value of $show before the query, and it's there
    PHP Code:
    $show $_POST['show'];
      echo
    "<p>Show: ".$show."</p>"
    Here is the query
    PHP Code:
      $sql "UPDATE category_programs SET
              name='
    $name',
              descrip_cat='
    $descrip_cat',
              img_cat='
    $img_cat',
              keywords_cat='
    $keywords_cat',
              text_cat='
    $text_cat',
              order_cat='
    $order_cat',
              visible='
    $visible',
              show='
    $show'
              WHERE id='
    $id'"
    I have also run and echoed the query without show='$show' and it works fine.

    Here is the form code:
    PHP Code:
    <p><label for="show">Show programs in the future, in the past, or all programs past and future.</label>
    <?php
    // Radio box for show
     //echo "<p>Show in form: " .$show."</p>";
    ?>
     <input type="radio" name="show" id="show" value="F"
     <?php
     
    if ($show =='F'){
     echo 
    "checked='checked'";
         }
    ?> /> 
     Future programs<br />

     <input type="radio" name="show" id="show" value="P" 
      <?php
     
    if ($show =='P'){
      echo 
    "checked='checked'";
        }
    ?> /> Past programs<br />
     
     <input type="radio" name="show" id="show" value="A" 
       <?php
     
    if ($show =='A'){
     echo 
    "checked='checked'";
         }
    ?> /> All programs, past and future<br />
    </p>
    The database field type is enum('F', 'P', 'B')
    What am I missing about the query error?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  9. #9
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  10. #10
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,383
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Re:
    show is the problem
    Thanks. I changed the field and variables to show_fpa, and all is well.
    Paul C.
    ClickBasics
    http://www.clickbasics.com


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
  •