php - isset() not giving expected results -
i have form
<form action="addnote.php" method="post"> <input type="hidden" name="tid" <?php echo"value='$id'"; ?> > <div class="input_fields_wrap1"> <label>note</label> <input type="text" id="coa" name="notes[]" > <button class="add_field_button1">add more notes</button> </div> <label>next call date</label> <input type="date" name="call" > <div class="form-group"> <label class="col-md-3 control-label" for="example-text-input"></label> <div class="col-md-3"> <input input type="submit" value="submit " > </div> </div> </form>
and php code
<?php include 'db.php'; $id=$_post['tid']; $notes=$_post['notes']; if(isset($_post['notes'])) { for($i=0;$i<count($notes);$i++) { $sql="insert notes (lead_id,note) value ('$id','$notes[$i]')"; $var=mysqli_query($conn, $sql); } } if(isset($_post['call'])) { $call=mysqli_real_escape_string($conn,$_post['call']); $sql="update lead set `call`='".$call."' lead_id='$id'"; $var=mysqli_query($conn, $sql); } header("location: remove_lead.php"); ?>
now, if don't fill date
or notes
text box, date
still gets updated 0000-00-00
, empty note stored in database.
but want is: if don't fill 1 or both of them, nothing should happen on php. did use isset()
correctly?
i changed suggested no use
if(!empty($_post['notes'])&&isset($_post['notes'])) { $notes=$_post['notes']; for($i=0;$i<count($notes);$i++) { $sql="insert notes (lead_id,note) value ('$id','$notes[$i]')"; $var=mysqli_query($conn, $sql); } } if(!empty($_post['call'])&&isset($_post['call'])) { $call=mysqli_real_escape_string($conn,$_post['call']); $sql="update lead set `call`='".$call."' lead_id='$id'"; $var=mysqli_query($conn, $sql); }
isset()
not check empty()
check whether variable or array or object set.
you need check empty
.
if(isset($_post['notes']) && !empty($_post['notes']))
Comments
Post a Comment