mysql - PHP post two values in one field, one of which is hidden -
is there way can post 2 values @ same time single field in table hide 1 user?
i following form post values id
, reason_name
when submitted have user able see (and edit in text box) reason_name
.
<form name="add_positioning" method="post" action="<?php echo $_server['php_self']; ?>"> <table border="1" class="autotable_pos"> <tr> <td>positioning</td><td> </td></tr> <? $sql= "select * gradereason reason_userid = $user_id , category = 'positioning' , current = 1"; $result = mysqli_query($mysqli,$sql) or die(mysqli_error($mysqli)); while($row = mysqli_fetch_array($result)){?> <tr> <td> <input type="text" name="reason[]" size="25" value="<? echo $row['reason_name']; ?>"/> </td> <td> <input type="button" value="delete" class="delrow_pos"/> </td> </tr> <? } ?> <tr> <td> <input type="text" name="reason[]" size="25"/> </td> <td> <input type="button" value="delete" class="delrow_pos"/> </td> </tr> <tr> <td colspan="2" align="right"> <input type="submit" value="save" name="save_reasons"/> </td> </tr> </table> </form>
the form post action far (basic echo @ moment own sanity check posts values correctly, does...)
if(isset($_post['save_reasons'])) { foreach($_post['reason'] $item) { echo $item.'<br/>'; } }
this table displays values held in database enables user add more values dynamically adding new row (using jquery
haven't included) table when type in empty 1 @ bottom , allows them edit or delete existing values.
for each value posted intend check if id
value empty, if means new value , enter new record database, if isn't update existing record in database corresponding id
. don't have problem writing bit, can't think how id
value posted reason_name
while keeping id
hidden user.
add id name attribute of text boxes of reasons loaded db. leave other text boxes added using jq without id. e.g. text box shows existing reason loaded db
<input type="text" name="reason[][id]" size="25"/>
text box added jq
<input type="text" name="reason[]" size="25"/>
then once submit form get following array.
array
'reason' => array 0 => array 14 => string 'val1' (length=4) 1 => string 'val2' (length=5)
by checking array in each element in "reason" array, can differentiate 2 type of text boxes.
here complete code have tested.
<?php //var_dump($_post); foreach($_post['reason'] $item=>$value) { if(is_array($value)){ foreach($value $id=>$reason) { echo "existing reason : ".$id." - ".$reason."<br>"; } } else{ echo "new reason : ".$item." - ".$value.'<br/>'; } } ?> <form action="" method="post"> <input type="text" name="reason[][14]" size="25" value="aaaa"/> <input type="text" name="reason[]" size="25" value="bbbbb"/> <input name="" type="submit"> </form>
Comments
Post a Comment