Checkbox hell
Results 1 to 2 of 2

Thread: Checkbox hell

  1. #1
    Senior Member
    Join Date
    May 2006

    Checkbox hell

    Hi all,

    Its late here and i have been staring at this for some time now. I simply want to input the values from two checkboxes into mysql. I can get the checkboxes to check when I submit the form, but the update to the table is not working, I am not getting any errors, including mysql ones when I screw up the query, but i cannot see why this is not working! the database connection is made and works fine as I have run a select query above this code and printed the results, I am sure it is something simple:

    PHP Code:
    if (isset($_POST['headlines']) != "true"){
        $headlines = "no";
        $headlines = "true";
    if (isset($_POST['family']) != "true"){
        $family = "no";
        $family = "true"; 

     if (isset($_POST['submit'])){
       $query = "UPDATE content_selection SET `headlines`='$headlines', `family`='$family' where userid='" . mysql_real_escape_string($userid) . "'";
    $result = mysql_query($query) or die('Update failed: ' . mysql_error()); 

    if (mysql_affected_rows() != 1) {
          //$link next to affected rows and mysql query
            echo "<p>Query = $query";  
            echo '<p>nothing</p>'; 
            echo '<p>$query</p>'; 
            echo '<p>result = $result</p>';
    <html lang="en">
      <meta charset="utf-8" />

      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
      <!--[if lt IE 9]><script src=""></script><![endif]-->

    <form name="UserInformationForm" method="POST" action="#">
          <input name="headlines" type="checkbox" value="true" <?php if($_POST['headlines']=="true") echo "checked=checked"?> > Headlines
          <input name="family" type="checkbox" value="true" <?php if($_POST['family']=="true") echo "checked=checked"?> > Family
          <input name="Submit" type="submit" value="Submit">

    Thanks for any help!


  2. #2
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    where do you define $userid?

    print your query to confirm its contents.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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