SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to split a query.

    A query has to get split according to whether a checkbox is clicked or not:

    PHP Code:
    INSERT INTO table
                
    (field1field2field3)
    VALUES      ('value1''value2')
     
    //-- now checking whether the checkbox has been clicked
     
    if (isset($_POST['checkbox']))
    {
        
    //-- add  'value3' to the values

    Field3 has a default value which should only get overwritten by value3, if checkbox has been activated.

    Well and that's the point where i'm stuck. How can i handle this?
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  2. #2
    SitePoint Addict
    Join Date
    Dec 2002
    Location
    Gent, Belgium, Europe, World, Univers
    Posts
    397
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $sql 'insert into table (field1, field2';
    if (isset(
    $_POST['checkbox'])) {
     
    $sql .= ', field3';
    }
    $sql .= ') values (\'value1\', \'value2\'';
    if (isset(
    $_POST['checkbox'])) {
     
    $sql .= ', \'value3\'';
    }
    $sql .= ')'
    Then print the query to see there aren't any errors

  3. #3
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i thought i also tried it the way you're providing it. Obviously i did something wrong, though.
    thanks alot, kajakske
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.


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
  •