Results 1 to 9 of 9

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User DonDale's Avatar
    Join Date: Nov:2008
    Location: Bulgaria
    Posts: 126

    Checkbox mySQL / PHP

    ,
    .
    ( ID, Name) checkbox VALUE ID . , . , ID ID .
    - , . , , . .
    .

  2. #2
    ! vbTheKing's Avatar
    Join Date: Sep:2003
    Location:
    Posts: 4,138
    name name="categories[]", value ID-, .. :
    <input type="checkbox" name="categories[]" value="1" />
    <input type="checkbox" name="categories[]" value="2" />
    <input type="checkbox" name="categories[]" value="3" />
    - $_POST['categories'] ( $_GET['categories']) foreach value-, - . , - .

    P.S. - html php , - .
    ''? * *
    - !
    ...

  3. #3
    Registered User DonDale's Avatar
    Join Date: Nov:2008
    Location: Bulgaria
    Posts: 126
    !!!

    if(isset($_POST['checkbox']))
    {
    foreach ($_POST['checkbox'] as $value){
    $checkbox= $_POST['checkbox'];
    $n = count($checkbox);
    $i = 0;
    }
    while ($i < $n)
    {
    $id_query = "INSERT into tbl(obj_id, category_id) VALUES ('$id_obj', '$checkbox[$i]]')";
    mysql_query($id_query) or die(mysql_error());
    $i++;
    }
    }

  4. #4
    ! vbTheKing's Avatar
    Join Date: Sep:2003
    Location:
    Posts: 4,138
    ?

    foreach .
    while for .
    .

    ---------- Post added at 18:42 ---------- Previous post was at 18:34 ----------

    . $id_obj , AUTO_INCREMENT, ID.
    category_id integer - $value .
    PHP Code:
    <?php

    if (isset($_POST['checkbox'])) {
        foreach (
    $_POST['checkbox'] as $value){
            
    //$value = mysql_real_escape_string($value); //         ,   integer
            
    $value intval($value);
            
    $id_query "INSERT into tbl(obj_id, category_id) VALUES ('$id_obj', '$value')";
            
    mysql_query($id_query) or die(mysql_error());
        }
    }

    ?>
    ''? * *
    - !
    ...

  5. #5
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    , , foreach -.
    foreach ($_POST['checkbox'] as $value) {
    // tuk wkarvash prosto w DB VALUES ($id_obj, $value)
    }

    $value integer, .

    vbTheKing:
    " $id_obj , AUTO_INCREMENT, ID."
    - --, . auto_increment , ID - - .


  6. #6
    Registered User DonDale's Avatar
    Join Date: Nov:2008
    Location: Bulgaria
    Posts: 126
    . $id_obj e ID . .
    !!!

  7. #7
    ! vbTheKing's Avatar
    Join Date: Sep:2003
    Location:
    Posts: 4,138
    , ... foreach . :
    $checkbox= $_POST['checkbox'];
    $n = count($checkbox);
    $i = 0;
    , -, .
    while- . - for , :
    for ($i=0; $i < $n; $i++) {

    }
    , . , , , () .
    ''? * *
    - !
    ...

  8. #8
    Registered User DonDale's Avatar
    Join Date: Nov:2008
    Location: Bulgaria
    Posts: 126
    Quote Originally Posted by vbTheKing View Post
    , ... foreach . :
    $checkbox= $_POST['checkbox'];
    $n = count($checkbox);
    $i = 0;
    , -, .
    while- . - for , :
    for ($i=0; $i < $n; $i++) {

    }
    , . , , , () .
    !!!
    !!!

  9. #9
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    DonDale, , , .
    PHP , , , , , , .
    , . .
    . , , 5 , 3 .. 5 .
    foreach , ?
    foreach for vbTheKing, - , , 5-10-20-50 . , , , security through obscurity .

Posting Permissions

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

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |