php - Inserting Value into database of hidden fields -


query if select 'select new parent category' dropdown, new textbox gets appear. wants insert value database. textbox hidden bydefault.

html file

<head>     <script type="text/javascript">                     $(document).ready(function() {       $('#parentcat').change(function(){       if($('#parentcat').val() === 'create new parent category')          {          $('#other').show();           $('#catname').hide();         }       else         {          $('#other').hide();           $('#catname').show();          }       });       });           </script>   </head>      <table>     <body>             <form method="post" action="" name="form1"  enctype="multipart/form-data" >                 <tr>                     <td><h4>add category</h4></td>                 </tr>                 <tr>                     <td>select parent category:</td><td><select name="parentcat" id="parentcat">                      <?php              include "../storescripts/connect_to_mysql.php";                         $result=mysql_query("select parent category"); while($row=mysql_fetch_array($result)){                             echo "<option>".$row['parent'];"</option>";                         } ?>                             <option value="create new parent category">create new parent category</option>                            </select><br/></td>                         <tr><td><input type="text" id="other" name="other" placeholder="new parent category name:" style="display: none;"/></td></tr>                   </tr>                  <tr>                     <td></td><td><input type="text" name="catname" placeholder="subcategory name" id="catname"><br/></td>                 </tr>                  <tr>                     <td>status:                     </td>                     <td><select name="status" >                         <option selected="active">active</option>                         <option>inactive</option>                     </select></td>                 </tr>                       <tr><td>category image :</td><td><input type="file" name="imageupload" id="imageupload"></td>                     </tr>                     <tr>                     <td></td>                     <td><input type="submit" name="submit" value="insert"></td>                     </tr>                   </form>                 </table> 

here complete html file,bydefault 'other' dropdown hidden. here i'm providing php code inserts values database, issue how can insert value of hidden filed database. database fields includes : cat_id(auto-increment),cat_name,parent,cat_status,cat_image. here php code inserting values database.

<?php                                   if(isset($_post['submit']))                                  {                                  $parentcat=$_post['parentcat'];                                 $catname=$_post['catname'];                             $status=$_post['status'];                                  $target_dir = "../uploads/";                                   $target_file = $target_dir . basename($_files["imageupload"]["name"]);                                   $uploadok = 1;                                   $imagefiletype = pathinfo($target_file,pathinfo_extension);                                      if (move_uploaded_file($_files["imageupload"]["tmp_name"], $target_file)) {                                         echo "the file ". basename( $_files["imageupload"]["name"]). " has been uploaded.";                                     } else {                                         echo "sorry, there error uploading file.";                                     }                                      $image=basename( $_files["imageupload"]["name"],".jpg"); // used store filename in variable                                   $sql = mysql_query("select cat_id category cat_name='$catname' limit 1");                                   $catmatch = mysql_num_rows($sql); // count output amount                                     if ($catmatch > 0) {                                     echo 'sorry tried place duplicate "category name" system, <a href="addcategoryy.php">click here</a>';                                     exit();                                    }                                    else{                                    $sql=mysql_query("insert `category` (`cat_name`, `parent`, `cat_status`,`cat_image`) values ('$catname', '$parentcat', '$status','$image') ");                                    echo $sql;                                 }                                  }  ?> 

for eg. if select new parent category subcategory named textbox appears , want insert value database. how can that.

change jquery code this

<script type="text/javascript"> $(document).ready(function () {     $('#parentcat').change(function () {          if ($('#parentcat').val() === 'create new parent category'){             $('#other').prop('type', 'text');             $('#catname').prop('type', 'hidden');         }         else{             $('#other').prop('type', 'hidden');             $('#catname').prop('type', 'text');          }     }); }); </script>  

also change html code #other input box this

<input type="hidden" id="other" name="other" placeholder="new parent category name:"/> 

let me know if works you.


edit

in php file, instead of $catname=$_post['catname']; add this

$catname = ( $parentcat == "create new parent category") ? $_post['other'] : $_post['catname']; 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -