I facing one issue. I need to remove total div using the id in Jquery while clicking on minus button. I am explaining my code below.
<?php foreach($module as $item){ ?>
<div id="planWithfriends<?php echo $item->id; ?>" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">PLAN WITH FRIENDS</h4>
</div>
<div class="modal-body">
<form class="row" action="" method="POST">
<div class="input_fields_wrap<?php echo $item->id; ?>">
<div id="parentid<?php echo $item->id; ?>">
<div class="form-group col-md-4">
<label class="go-right" style="margin-bottom:0px;">Email </label>
<input name="email_<?php echo $item->id; ?>[]" id="email_<?php echo $item->id; ?>" type="text" class="form-control input_style1" placeholder="" value="" style="height:34px;">
</div>
<div class="form-group col-md-4">
<label class="go-right" style="margin-bottom:0px;">Phone </label>
<input name="phone_<?php echo $item->id; ?>[]" id="phone_<?php echo $item->id; ?>" type="text" class="form-control input_style1" placeholder="" value="" style="height:34px;">
</div>
<div class="form-group col-md-4">
<button type="button" class="add_button_<?php echo $item->id; ?> btn btn-success" style="height:34px;margin-top: 20px;"><i class="fa fa-plus"></i></button>
</div>
</div>
</div>
<div class="clear"></div>
<div class="form-group col-md-12 text-right">
<button style="margin-top:25px;" type="button" class="btn btn-action" data-dismiss="modal" id="planbutton<?php echo $item->id; ?>">Submit</button>
</div>
<div class="clear"></div>
</form>
</div>
<!--<div class="modal-footer" style="text-align:center;">
<button type="button" class="btn btn-action" data-dismiss="modal">Close</button>
</div>-->
</div>
</div>
</div>
<script type="text/javascript">
$(function(){
var addButton = $('.add_button_<?php echo $item->id; ?>');
var wrapper = $('.input_fields_wrap<?php echo $item->id; ?>');
$(addButton).click(function(){
$(wrapper).append('<div id="parentid<?php echo $item->id; ?>"><div class="form-group col-md-4"><input name="email_<?php echo $item->id; ?>[]" id="email_<?php echo $item->id; ?>" type="text" class="form-control input_style1" placeholder="" value="" style="height:34px;"></div><div class="form-group col-md-4"><input name="phone_<?php echo $item->id; ?>[]" id="phone_<?php echo $item->id; ?>" type="text" class="form-control input_style1" placeholder="" value="" style="height:34px;"></div><div class="form-group col-md-4"><button type="button" class="remove_field<?php echo $item->id; ?> btn btn-danger" style="height:34px;margin-top: 20px;"><i class="fa fa-minus"></i></button></div></div>'); //
})
$(wrapper).on('click', '.remove_field<?php echo $item->id; ?>', function(e){
e.preventDefault();
$(this).parent('#parentid<?php echo $item->id; ?>').remove();
})
})
</script>
<?php } ?>
Here I creating another row clicking on + button but when user will click on - button the respective row should remove which is not happening in my case. Please help me to resolve this issue.
As I have seen you put JavaScript code inside the loop. Please put it outside the loop as:
<script type="text/javascript">
$(function(){
var addButton = $('.add_button');
var wrapper = $('.input_fields_wrap');
$(addButton).click(function(){
$(wrapper).append('<div id="parentid"><div class="form-group col-md-4"><input name="email_<?php echo $item->id; ?>[]" id="email_<?php echo $item->id; ?>" type="text" class="form-control input_style1" placeholder="" value="" style="height:34px;"></div><div class="form-group col-md-4"><input name="phone_<?php echo $item->id; ?>[]" id="phone_<?php echo $item->id; ?>" type="text" class="form-control input_style1" placeholder="" value="" style="height:34px;"></div><div class="form-group col-md-4"><button type="button" class="remove_field<?php echo $item->id; ?> btn btn-danger" style="height:34px;margin-top: 20px;"><i class="fa fa-minus"></i></button></div></div>'); //
})
$(wrapper).on('click', '.remove_field', function(e){
e.preventDefault();
$(this).parent('.parentid').remove();
})
})
</script>
and give a class remove_field when clicking on it get parent div class and do whatever you want. This is not good practicing to put JavaScript inside the PHP loop.
Related
i have a project in php codeigniter where data is fetched from the DB, and with a foreach loop it creates rows in a table, each row has an edit button that opens the fancybox modal, in that modal i have 2 input fields, first name and last name that i try to populate them with the current values from the database, in the value section i tried value="<?php echo $row->first_name ?>, the problem is that all the rows get the same value, the modal does not get the correct data for each row.
Relevant code:
<a data-fancybox data-touch="false" href="#modal" class="btn btn-secondary" style=" margin-bottom:5px;" id="<?php echo $row->id; ?>" type="button" name="button">Edit</a>
<div id="modal">
<div class="content">
<div class="container-fluid">
<div class="row">
<form method="post" action="<?php echo base_url()?>index.php/welcome/formValidation">
<div class="form-row">
<div class="col-12 mb-3">
<h3 class="mb-3">Modifica Rapid:</h3>
<label for="nume">Nume:</label>
<input type="text" class="form-control" id="nume" placeholder="Nume" name="nume" value="<?php echo $row->last_name ?>"required>
</div>
<div class="col-12 mb-3">
<label for="prenume">Prenume</label>
<input type="text" class="form-control" id="prenume" placeholder="Prenume" name="prenume" value="<?php echo $row->first_name ?>" required>
</div>
<div class="col-12 mb-3 text-center">
<button style="width:150px;height:50px;" class="btn btn-warning" type="submit">Modifica</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
What you need to do is, attach the $row id to the modal css id so each modal is unique.
<a data-fancybox data-touch="false" href="#modal<?=$row->id;?>" class="btn btn-secondary" style=" margin-bottom:5px;" id="<?php echo $row->id; ?>" type="button" name="button">Edit</a>
<div id="modal<?=$row->id;?>">
<div class="content">
<div class="container-fluid">
<div class="row">
<form method="post" action="<?php echo base_url()?>index.php/welcome/formValidation">
<div class="form-row">
<div class="col-12 mb-3">
<h3 class="mb-3">Modifica Rapid:</h3>
<label for="nume">Nume:</label>
<input type="text" class="form-control" id="nume" placeholder="Nume" name="nume" value="<?php echo $row->last_name ?>"required>
</div>
<div class="col-12 mb-3">
<label for="prenume">Prenume</label>
<input type="text" class="form-control" id="prenume" placeholder="Prenume" name="prenume" value="<?php echo $row->first_name ?>" required>
</div>
<div class="col-12 mb-3 text-center">
<button style="width:150px;height:50px;" class="btn btn-warning" type="submit">Modifica</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
So change
<a data-fancybox data-touch="false" href="#modal" class="btn btn-secondary" style=" margin-bottom:5px;" id="<?php echo $row->id; ?>" type="button" name="button">Edit</a>
to
<a data-fancybox data-touch="false" href="#modal<?=$row->id;?>" class="btn btn-secondary" style=" margin-bottom:5px;" id="<?php echo $row->id; ?>" type="button" name="button">Edit</a>
by adding the row id to the css to get unique modal id if not all link will call only the last modal.
The same change too for the modal change
<div id="modal">
to
<div id="modal<?=$row->id;?>">
One of the workaround is you could assign data attributes containing the last_name and first_name data, and add an edit-btn class (as the trigger) to the edit button link :
<a data-fancybox data-touch="false" href="#modal" class="btn btn-secondary edit-btn" data-lastName="<?php echo $row->last_name ?>" data-firstName="<?php echo $row->first_name ?>" style=" margin-bottom:5px;" id="<?php echo $row->id; ?>" type="button" name="button">Edit</a>
<div id="modal">
<div class="content">
<div class="container-fluid">
<div class="row">
<form method="post" action="<?php echo base_url()?>index.php/welcome/formValidation">
<div class="form-row">
<div class="col-12 mb-3">
<h3 class="mb-3">Modifica Rapid:</h3>
<label for="nume">Nume:</label>
<input type="text" class="form-control" id="nume" placeholder="Nume" name="nume" required>
</div>
<div class="col-12 mb-3">
<label for="prenume">Prenume</label>
<input type="text" class="form-control" id="prenume" placeholder="Prenume" name="prenume" required>
</div>
<div class="col-12 mb-3 text-center">
<button style="width:150px;height:50px;" class="btn btn-warning" type="submit">Modifica</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
Then set the modal input value using each of the data value :
$(document).on("click", ".edit-btn", function () {
let lastname = $(this).attr("data-lastname");
let firstname = $(this).attr("data-firstname");
$('#nume').val(lastname); // set the lastname input inside the modal using the data attribute
$('#prenume').val(firstname); // set the firstname input inside the modal using the data attribute
});
I am very confused by errors in this program, can you help me?
And this is a process WITH php:
$nm_pel = $_POST['nm_pelanggan'];
$alamat = $_POST['alamat'];
$telepon = $_POST['telepon'];
$email = $_POST['email'];
$id_pelanggan = $_POST['id_pelanggan'];
$sql = "UPDATE pelanggan SET nm_pelanggan='$nm_pel',alamat='$alamat',telepon='$telepon',email='$email' WHERE id_pelanggan='$id_pelanggan' ";
mysqli_query($link,$sql);
and this is a function ajax:
function updateData(str){
var id_pelanggan = str;
var nm_pelanggan = $('#nm-'+str).val();
var alamat = $('#alt-'+str).val();
var telepon = $('#tlp-'+str).val();
var email =$('#em-'+str).val();
$.ajax({
type : 'POST',
url : 'core/process.php?p=edit',
data : "nm_pelanggan="+nm_pelanggan+"&alamat="+alamat+"&telepon="+telepon+"&email="+email+"&id_pelanggan="+id_pelanggan,
success : function(data){
viewData();
}
});
}
Your javascript ajax function appears misformatted. May I recommend correcting the constructor for the data you send as follows? Hope this helps.
$.ajax({
type : 'POST',
url : 'core/process.php?p=edit',
data : {nm_pelanggan:nm_pelanggan, alamat:alamat, telepon:telepon, email:email, id_pelanggan:id_pelanggan},
success : function(data){
viewData();
}
});
and this code form edit data :
<div class="modal fade" id="edit-<?php echo $row['id_pelanggan']; ?>" tabindex="-1" role="dialog" aria-labelledby="editLabel-<?php echo $row['id_pelanggan']; ?>">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id=editLabel-"<?php echo $row['id_pelanggan'];?>">Edit Data Pelanggan <?php echo $row['id_pelanggan']; ?> </h4>
</div>
<form>
<div class="modal-body">
<div class="form-group ">
<label class="control-label requiredField" for="id_pelanggan">
Kode Pelanggan
<span class="asteriskField">
*
</span>
</label>
<input class="form-control" id="<?php echo $row['id_pelanggan']; ?>" value="<?php echo $row['id_pelanggan']; ?>" type="text" disabled>
</div>
<div class="form-group ">
<label class="control-label " for="nm_pelanggan">
Nama Pelanggan
</label>
<input class="form-control" id="nm-<?php echo $row['id_pelanggan']; ?>" value="<?php echo $row['nm_pelanggan']; ?>" type="text">
</div>
<div class="form-group ">
<label class="control-label " for="alamat">
Alamat
</label>
<input class="form-control" id="alt-<?php echo $row['id_pelanggan'];?>" value="<?php echo $row['alamat'];?>" type="text">
</div>
<div class="form-group ">
<label class="control-label " for="telepon">
Nomor HP
</label>
<input class="form-control" id="tlp-<?php echo $row['id_pelanggan'];?>" value="<?php echo $row['telepon'];?>" type="text">
</div>
<div class="form-group ">
<label class="control-label " for="email">
Email
</label>
<input class="form-control" id="em-<?php echo $row['id_pelanggan'];?>" value="<?php echo $row['email']; ?>" type="email">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Batal</button>
<button type="submit" onclick="updateData(<?php echo $row['id_pelanggan']; ?>)" class="btn btn-primary" >Edit Data</button>
</div>
</form>
</div>
</div>
</div>
</div>
At the backend of my opencart e-commerce package, there is the possibility to insert vouchers for customers. However, there is standard no possibility to set a start and end date (1 year later) for the voucher. Therefore I have adapted the voucher.tpl template to include this possibility. I have implemented this completely identical as for the coupon.tpl where there is the possibility to enter a start date and end date.
The input field for the start date and end date is using the datetimepicker script. The datepicker is showing up correctly when I click the calendar button (see image 1) and the date is showing up.
The dates are used in a form, but unfortunately the data seem not be transferred with the form when the save button is clicked. I see no difference with the coupon.tpl page where everything is working properly. I spent already many hours in founding the error but did not succeed yet. Could somebody help me on my way?
Thanks,
SabKo
The voucher.tpl has the following code:
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right">
<button type="submit" form="form-voucher" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
<i class="fa fa-reply"></i>
</div>
<h1><?php echo $heading_title; ?></h1>
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><?php echo $breadcrumb['text']; ?></li>
<?php } ?>
</ul>
</div>
</div>
<div class="container-fluid">
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<?php } ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_form; ?></h3>
</div>
<div class="panel-body">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-voucher" class="form-horizontal">
<div class="tab-content">
<div class="tab-pane active" id="tab-general">
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-code"><span data-toggle="tooltip" title="<?php echo $help_code; ?>"><?php echo $entry_code; ?></span>
</label>
<div class="col-sm-10">
<input type="text" name="code" value="<?php echo $code; ?>" placeholder="<?php echo $entry_code; ?>" id="input-code" class="form-control" />
<?php if ($error_code) { ?>
<div class="text-danger"><?php echo $error_code; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-from-name"><?php echo $entry_from_name; ?>
</label>
<div class="col-sm-10">
<input type="text" name="from_name" value="<?php echo $from_name; ?>" placeholder="<?php echo $entry_from_name; ?>" id="input-from-name" class="form-control" />
<?php if ($error_from_name) { ?>
<div class="text-danger"><?php echo $error_from_name; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-to-name"><?php echo $entry_to_name; ?></label>
<div class="col-sm-10">
<input type="text" name="to_name" value="<?php echo $to_name; ?>" placeholder="<?php echo $entry_to_name; ?>" id="input-to-name" class="form-control" />
<?php if ($error_to_name) { ?>
<div class="text-danger"><?php echo $error_to_name; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-amount"><?php echo $entry_amount; ?></label>
<div class="col-sm-10">
<input type="text" name="amount" value="<?php echo $amount; ?>" placeholder="<?php echo $entry_amount; ?>" id="input-amount" class="form-control" />
<?php if ($error_amount) { ?>
<div class="text-danger"><?php echo $error_amount; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-date-start"><?php echo $entry_date_start; ?></label>
<div class="col-sm-3">
<div class="input-group date">
<input type="text" name="date_start" value="<?php echo $date_start; ?>" placeholder="<?php echo $entry_date_start; ?>" data-date-format="YYYY-MM-DD" id="input-date-start" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-date-end"><?php echo $entry_date_end; ?></label>
<div class="col-sm-3">
<div class="input-group date">
<input type="text" name="date_end" value="<?php echo $date_end; ?>" placeholder="<?php echo $entry_date_end; ?>" data-date-format="YYYY-MM-DD" id="input-date-end" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
</div>
<?php if ($voucher_id) { ?>
<div class="tab-pane" id="tab-history">
<div id="history"></div>
</div>
<?php } ?>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript"><!--
$('.date').datetimepicker({
pickTime: false
});
//--></script>
</div>
The controller page has the following code, so should be able to read the input of the dates:
if (isset($this->request->post['date_start'])) {
$data['date_start'] = $this->request->post['date_start'];
} elseif (!empty($voucher_info)) {
$data['date_start'] = ($voucher_info['date_start'] != '0000-00-00' ? $voucher_info['date_start'] : '');
} else {
$data['date_start'] = date('Y-m-d', time());
}
if (isset($this->request->post['date_end'])) {
$data['date_end'] = $this->request->post['date_end'];
} elseif (!empty($voucher_info)) {
$data['date_end'] = ($voucher_info['date_end'] != '0000-00-00' ? $voucher_info['date_end'] : '');
} else {
$data['date_end'] = date('Y-m-d', strtotime('+1 month'));
}
You're initialize your datetime picker on div with class .date but you have to initialize it on inputs with their classes or ids.
replace this code:
<script type="text/javascript"><!--
$('.date').datetimepicker({
pickTime: false
});
//--></script>
with this one:
<script type="text/javascript"><!--
$('#input-date-start').datetimepicker({
pickTime: false
});
$('#input-date-end').datetimepicker({
pickTime: false
});
//--></script>
I am wondering why the code only works on the last row of the message reply, I can't reply on the latest message but I can reply on the last message, the messages are descending.
Please take a look at messages.php:
<form action="read_message.php" method="post">
<div class="pull-right">
<button class="btn btn-info" name="read"><i class="icon-check"></i> Read</button>
Check All <input type="checkbox" name="selectAll" id="checkAll" />
<script>
$("#checkAll").click(function () {
$('input:checkbox').not(this).prop('checked', this.checked);
});
</script>
</div>
<ul class="nav nav-pills">
<li class="active"><i class="icon-envelope-alt"></i>inbox</li>
<li class=""><i class="icon-envelope-alt"></i>Send messages</li>
</ul>
<?php
$query_announcement = mysql_query("select * from message_received
LEFT JOIN user ON user.user_id = message_received.user_id
where message_received.receiver_id = '$session_id' order by date_sent DESC
")or die(mysql_error());
$count_my_message = mysql_num_rows($query_announcement);
if ($count_my_message != '0') {
while ($row = mysql_fetch_array($query_announcement)) {
$id = $row['message_id'];
$id_2 = $row['message_id'];
$fn = $row['firstname'];
$ln = $row['lastname'];
$status = $row['message_status'];
$sender = $row['user_id'];
$sender_name = $fn . ' ' . $ln;
$receiver = $row['receiver_id'];
?><div class="alert alert-info">
<div class="post" id="del<?php echo $id; ?>">
<div class="message_content">
<?php echo $row['content']; ?>
</div>
<div class="pull-right">
<?php if ($status == 'read') {
} else {
?>
<input id="" class="" name="selector[]" type="checkbox" value="<?php echo $id; ?>">
<?php } ?>
</div>
<hr>
Send by: <strong><?php echo $fn . ' ' . $ln; ?></strong>
<i class="icon-calendar"></i> <? php echo $row['date_sent']; ?>
<div class="pull- right">
<a class="btn btn-link" href="#reply<?php echo $id; ?>" data-toggle="modal" ><i class="icon-reply"></i> Reply </a>
</div>
<div class="pull-right">
<a class="btn btn-link" href="#<?php echo $id; ?>" data-toggle="modal" ><i class="icon-remove"></i> Remove </a>
<?php include("remove_inbox_message_modal.php"); ?>
<?php include("reply_inbox_message_modal_user.php"); ?>
</div>
</div>
</div>
<?php }
} else { ?>
<div class="alert alert-info"><i class="icon- info-sign"></i> No Message Inbox</div>
<?php } ?>
</form>
NOW THIS is the function for read_message.php, I can't see any error, please help me.
<?php
if (isset($_POST['reply'])) {
$sender = $_POST['sender'];
$receiver = $_POST['receiver'];
$my_message = $_POST['my_message'];
mysql_query("insert into message_received (user_id,receiver_id,content,date_sent) values('$receiver','$sender','$my_message',NOW())")or die(mysql_error());
mysql_query("insert into message_sent (receiver_id,content,date_sent,user_id) values('$sender','$my_message',NOW(),'$receiver')")or die(mysql_error());
echo "<script> alert('Your message has been sent $my_message') </script>";
echo " <script>location.replace('messages.php')</script>";
?>
<script>
alert('Message Sent');
window.location = "messages.php";
</script>
<?php
}
?>
now this is the reply modal codes,
<!-- Modal -->
<div id="reply<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria- hidden="true">x</button>
<h3 id="myModalLabel">Reply</h3>
</div>
<div class="modal-body">
<center>
<div class="control-group">
<label class="control-label" for="inputEmail">To:</label>
<div class="controls">
<input type="hidden" name="sender" id="inputEmail" value="<?php echo $sender; ?>" readonly>
<input type="hidden" name="receiver" id="inputEmail" value="<?php echo $receiver; ?>" readonly>
<input type="hidden" name="uid" id="inputEmail" value="<?php echo $uid; ?>" readonly>
<input type="hidden" name="my_name" value="<?php echo $reciever_name; ?>" readonly>
<input type="text" name="name_of_sender" id="inputEmail" value="<?php echo $sender_name; ?>" readonly>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Content:</label>
<div class="controls">
<textarea name='my_message'></textarea>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" name="reply" id="<?php echo $id; ?>" class="btn btn-success reply"><i class="icon-reply"></i> Reply</button>
</div>
</div>
</center>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove icon-large"></i> Close</button>
<button id="<?php echo $id; ?>" class="btn btn-danger remove" data- dismiss="modal" aria-hidden="true"><i class="icon-check icon-large"></i> Yes </button>
</div>
when I reply to a message the message is sent but it has no content but data from sender, date and time is saved in the database, but in the lowest row, it all functions well? please help me. thank you
You have it your message modal window in one form.
So your solution works only if you have only one message. If you have more messages when you send your response send all responses for each message (its one form) and each response content have same name.
For this reason your server obtains empty $_POST['my_message']
You need have for each response own form and it will works. like this:
<form action="read_message.php" method="post">
<!-- Modal -->
<div id="reply<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria- hidden="true">x</button>
<h3 id="myModalLabel">Reply</h3>
</div>
<div class="modal-body">
<center>
<div class="control-group">
<label class="control-label" for="inputEmail">To:</label>
<div class="controls">
<input type="hidden" name="sender" id="inputEmail" value="<?php echo $sender; ?>" readonly>
<input type="hidden" name="receiver" id="inputEmail" value="<?php echo $receiver; ?>" readonly>
<input type="hidden" name="uid" id="inputEmail" value="<?php echo $uid; ?>" readonly>
<input type="hidden" name="my_name" value="<?php echo $reciever_name; ?>" readonly>
<input type="text" name="name_of_sender" id="inputEmail" value="<?php echo $sender_name; ?>" readonly>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Content:</label>
<div class="controls">
<textarea name='my_message'></textarea>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" name="reply" id="<?php echo $id; ?>" class="btn btn-success reply"><i class="icon-reply"></i> Reply</button>
</div>
</div>
</center>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove icon-large"></i> Close</button>
<button id="<?php echo $id; ?>" class="btn btn-danger remove" data- dismiss="modal" aria-hidden="true"><i class="icon-check icon-large"></i> Yes </button>
</div>
</form>
PHP variables are not parsed in single quotes. You need to update your SQL queries to use double quotes, or no quotes, with your PHP variables.
insert into message_sent (receiver_id,content,date_sent,user_id) values("$sender","$my_message",NOW(),"$receiver")
That is why only the date is saving.
Clear the messages in your database, update the queries (multiple) and try again. Then, report back with an update and I'll take another look at it.
I am trying to complete the project today but i figured it out that the edit function which i wrote was not working as every button i click on the edit it displays the same values. I needed to show the respective data to display in one particular modal.
Here is what i had done:
<?php
foreach ($allhealthlist as $row):
echo '<tr>';
echo '<td>' . $row['HI Name'] . '</td>';
echo '<td>' . $row['Ownership'] . '</td>';
echo '<td>' . $row['District'] . '</td>';
echo '<td>' . $row['VDC'] . '</td>';
echo '<td>' . $row['Type'] . '</td>';
echo '<td>';
?>
<div class="col-md-1">
<div id="myModal" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<a class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span></a>
<h4 class="modal-title" id="myModalLabel">Heath Institute</h4>
</div>
<div class="modal-body">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title"><strong>Edit Information </strong></h3></div>
<div class="panel-body">
<form role="form">
<div class="form-group">
<label class="hide">ID</label>
<input type="email" class="form-control hide" id="exampleInputEmail1" name="healtid" value="<?php echo $row['ID']; ?>">
</div>
<div class="form-group">
<label for="exampleInputEmail1">HI Name</label>
<input type="email" class="form-control" id="exampleInputEmail1" name="healthname" value="<?php echo $row['HI Name']; ?>">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Ownership</label>
<input type="email" class="form-control" id="exampleInputEmail1" name="ownership" value="<?php echo $row['HI Name']; ?>">
</div>
<div class="form-group">
<label for="exampleInputPassword1">District</label>
<input type="password" class="form-control" id="exampleInputPassword1" name="district" value="<?php echo $row['HI Name']; ?>">
</div>
<div class="form-group">
<label for="exampleInputPassword1">VDC</label>
<input type="password" class="form-control" id="exampleInputPassword1" name="vdc" value="<?php echo $row['HI Name']; ?>">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Type</label>
<input type="password" class="form-control" id="exampleInputPassword1" name="type" value="<?php echo $row['HI Name']; ?>">
</div>
</form>
</div>
</div>
</div>
<div class="modal-footer">
<div class="btn-group">
<button class="btn btn-danger" data-dismiss="modal">Cancel</button>
<button class="btn btn-primary">Update</button>
</div>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dalog -->
</div><!-- /.modal -->
<a data-toggle="modal" href="#myModal" class="btn btn-primary" >Edit</a>
</div>
<?php
echo '</td>';
endforeach;
?>
For my opinion better is to save your data in JavaScript object, then when you open Modal you can set those values where you want.