#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    77
    Rep Power
    15
    I am currently working on a phonebook system whereby people can add their own names to the database. So I also have an edit facility. Within my form however I have 3 checkboxes. What I need to know is say someone clears their checkbox, how do I get that to clear the table field?? At the moment, if they de-select the field then it adds it doesn't change the field. Also note, i created a separate column for each of the checkbox fields (they are called roles1, roles2, and roles3). I have included my code for how I can tell if the box should be checked or not. Thanks for your help.

    Dave

    <?php
    // Check Box 1
    echo "<input type='checkbox' name='roles1' value='EH&amp;S Representative' ";

    if (ereg("EH&S Representative", $myrow[roles1]))
    {
    # if database field value =yes then

    echo "checked";
    }
    printf (">EH&S Representative");

    ?>
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    see ,,, you can find out wether user has selected the check box or not using isset() function

    eg:

    if (!isset(roles1)){
    $roles1="Not Selected";
    }

    $result=mysql_query("UPDATE phonebook set roles1='$roles1'",$con);

    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited June 01, 2000).]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    77
    Rep Power
    15
    Can you see any reason why the following script would not update my database when each of the field is past to it? I had it working earlier but have found now that nothing is being updated...

    <?php

    // setup database connection

    $db = mysql_connect("localhost", "root");

    // specify database to use

    mysql_select_db("development",$db);

    // specify query to use

    mysql_query("UPDATE staff SET
    fname = $fname,
    sname = $sname,
    location = $location,
    dept = $dept,
    report = $report,
    btitle = $btitle,
    phone_extension = $phone_extension,
    phone_int = $phone_int,
    phone_ext = $phone_ext,
    fax = $fax,
    phone_mob = $phone_mob,
    alt_email = $alt_email,
    roles1 = $roles1
    roles2 = $roles2
    roles3 = $roles3
    WHERE fname=$fname AND sname=$sname");

    print ("<font size='2' face='Frutiger, Verdana, Arial, Helvetica, sans-serif'>");
    print ($fname);
    echo $mysql_query;
    print (" ");
    print ($sname);
    print ("<p>");
    print ("Details have been added!");
    print ("</font>");
    ?>
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Query is wrong..you missed commas.


    <<
    roles1 = $roles1
    roles2 = $roles2
    roles3 = $roles3
    WHERE fname=$fname AND sname=$sname


    try this:


    mysql_query("UPDATE staff SET
    fname = $fname,
    sname = $sname,
    location = $location,
    dept = $dept,
    report = $report,
    btitle = $btitle,
    phone_extension = $phone_extension,
    phone_int = $phone_int,
    phone_ext = $phone_ext,
    fax = $fax,
    phone_mob = $phone_mob,
    alt_email = $alt_email,
    roles1 = $roles1,
    roles2 = $roles2,
    roles3 = $roles3,
    WHERE fname=$fname AND sname=$sname");


    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."



    [This message has been edited by Shiju Rajan (edited June 01, 2000).]
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    109
    Rep Power
    15
    If this doesn't work you must put all variables between parenthesis, like:

    mysql_query("UPDATE staff SET
    fname = '$fname',
    sname = '$sname',
    location = '$location',
    .
    .
    .
    roles1 = '$roles1',
    roles2 = '$roles2',
    roles3 = '$roles3',
    WHERE fname='$fname' AND sname='$sname'");

    [This message has been edited by pwluky (edited June 01, 2000).]
  10. #6
  11. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    If this doesn't work you must put all variables between parenthesis, like:


    That is right. you should do that....
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    77
    Rep Power
    15
    Thanks guys, that worked the treat. I originally did have the single quotes but in my desperate attempt to sort out what was going on I took them out. All appears to be working perfectly now. Thanks again!

Similar Threads

  1. Getting checkbox data, inserting in DB
    By crazyIvan in forum PHP Development
    Replies: 6
    Last Post: January 29th, 2004, 08:45 AM
  2. Replies: 2
    Last Post: January 8th, 2004, 04:55 AM
  3. Mind Boggling Serialization Error
    By bergy in forum Visual Basic Programming
    Replies: 3
    Last Post: January 6th, 2004, 02:13 PM
  4. Grayed Out but enabled checkbox
    By thomasdayton123 in forum HTML Programming
    Replies: 0
    Last Post: November 14th, 2003, 10:30 PM
  5. checkbox assistance needed
    By linhardt in forum HTML Programming
    Replies: 6
    Last Post: October 2nd, 2003, 12:19 PM

IMN logo majestic logo threadwatch logo seochat tools logo