mysql - PHP checklist get ID and value and store it -


so have form add new item database checkbox follows

enter image description here

enter image description here

so difficulty checkbox. can enough create array items checked need id them along it. i've tried think of many ways , searched lot can't think of way id in way useable me along name of feature (checklist). since have each feature item , add table houses_has_features.

<?php $title = 'add new house'; require_once 'header.php'; require_once 'nav.php'; require_once 'mysqli-con.php';  $conn = new mysqli($hn, $un, $pw, $db);  // if house name , type set add them database if( !empty($_post['h_name']) && !empty($_post['h_type']) ) {     $house_name = $conn->real_escape_string($_post['h_name']);     $house_type = $conn->real_escape_string($_post['h_type']);      //show names added     echo '<b>house name: </b>'.$house_name . '<br><b> house type:</b>  ' . $house_type;      $query = "insert `house_names` (`id`, `name`) values (null, '$house_name')";     $result = $conn->query($query);     if (!$result) die ("<b class='text-danger'><p>insert failed errror: " . $conn->error. "</p>");      global $house_name_id;     $house_name_id = $conn->insert_id;     $query = "insert `house_types` values ('$house_name_id', '$house_type')";     $result = $conn->query($query);     if (!$result) die ("<b class='text-danger'><p>insert failed errror: " . $conn->error. "</p>");     } else {     global $house_name_id;     $house_name_id= null;     }    //start container page content echo '<div class="container">';  //display error message if house name filled in not house type if ( !empty($_post['h_name']) && empty($_post['h_type']) || empty($_post['h_name']) && !empty($_post['h_type']) ) {     echo "<p class='error-text'>* please fill in both house name , house type *</p>"; }     $query_feat = $conn->query('select * features'); $rows = $query_feat->num_rows;   $features_list  = $_post['check_list']; $feature_id = $_post['feature_id']; //display checked boxes. if(isset($_post['check_list'])) {     ($i=0; $i<sizeof($features_list); $i++){          //echo '<br>house name id:' . $house_name_id . '<br> $_post[] = ' . "$features_list[]";         print_r($features_list); echo '<br>';         print_r($feature_id);     } }     // add house form echo <<<_end       <h1>add house</h1> </div> <div class="container">     <form action="add.php" method="post">         <p>house name: <input type="text" name="h_name"></p>         <p>house type: <input type="text" name="h_type"></p>         <b>features:</b>          <ul class="list-group"> _end;         ($c = 0 ; $c < $rows ; ++$c){          $query_feat->data_seek($c);         $feat = $query_feat->fetch_array(mysqli_num);           echo '<li><input type="checkbox" name="check_list[]" value="' .$feat[1]. '">'.$feat[1].'</li>';  }   echo <<<_end         <ul>         <input class="btn-primary" type="submit" value="submit">     </form> </div>  _end;    require_once 'footer.php'; 

i'm lost on 1 appreciated :)

change value of checkbox id or want.

<li><input type="checkbox" name="check_list[]" value="' .$feat[0]. '">'.$feat[1].'</li> 


$feat[1] => $feat[0] or else


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -