How can i pass values in a modal in bootstrap? - php

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.

Related

How to Update Mysql Data with a button on Home Page that is passing id on URL?

I have created an Edit Item popup Bootstrap modal on home page. Now what I want is to update the selected item details using the PHP.
Here i am passing item id through the URL in order to select the item
Now when I press edit Button it opens a Popup with all the details in it( already filled) but when I try to click on Save Changes Button it just do nothing and My data not updated. I have also used POST method but its not working.
Here is the Button that opens the Popup Modal
<?php
$res= mysqli_query($db,"SELECT* FROM `books`;");
if(mysqli_num_rows($res)>0){
while($row= mysqli_fetch_assoc($res)){
if($row!=0)
{
$bid= $row['book_id'];
?>
<ul>
<li>
<a onclick="$('#editModal<?php echo $row['book_id']?>').modal('show');" class="btn-show-modal edit-btn" data-toggle="modal"><i style="padding-right: 140px;" class="fas fa-edit"></i></a>
</li>
<!--Here is the Popup Modal for Edit -->
<div id="editModal<?php echo $row['book_id']?>" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit This Book</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="updatebook.php" method="POST">
<div class="form-group">
<label for="isbn" class="col-form-label">ISBN</label>
<input type="text" class="form-control" name="isbn" value="<?php echo $row['isbn'];?>">
</div>
<div class="form-group">
<label for="title" class="col-form-label">Enter Book Title</label>
<input type="text" class="form-control" name="title" value="<?php echo $row['title'];?>">
</div>
<div class="form-group">
<label for="author" class="col-form-label">Enter Author Name</label>
<input type="text" class="form-control" name="author" value="<?php echo $row['author'];?>">
</div>
<div class="form-group">
<label for="image" class="col-form-label">Image URL</label>
<input type="text" class="form-control" name="image" value="<?php echo $row['image'];?>">
</div>
<div class="form-group">
<label for="description" class="col-form-label">Enter Book Description</label>
<textarea class="form-control" name="description" value="<?php echo $row['description'];?>"></textarea>
</div>
<div class="form-group">
<label for="url" class="col-form-label">Book URL</label>
<input type="text" class="form-control" name="url" value="<?php echo $row['url'];?>"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" name="save">Save Changes</button>
</div>
</div>
</div>
</div>
<?php
}
}
}
else
{
echo"<h1 style='color: white;font-size:58px; font-family: Poppins; font-weight: 600;' class=m-2>U!Oh Nothing Found Here!</h1>
<button onclick=\"window.location.href='add_books_form.php'\" class=\"btn btn-info bg-primary m-5\">Contribute</button>";
}
?>
</ul>
Here is the updatebook.php Page
<?php
include "connection.inc.php";
if(isset($_POST['save']))
{
$id= $_POST['id'];
$isbn= $_POST['isbn'];
$title= $_POST['title'];
$author= $_POST['author'];
$image= $_POST['image'];
$desc= $_POST['description'];
$url= $_POST['url'];
$res = mysqli_query($db, "UPDATE books SET isbn= '$isbn', title= '$title', author= '$author',image= '$image', description= '$desc', url= '$url' WHERE book_id= '$id'");
?>
if($res)
{
<script type="text/javascript">
alert("Data Updated Successfully");
window.location.href= "home.php";
</script>
}
else
{
<script>
alert("Not Updated!");
window.location.href="home.php";
</script>
}
<?php
}
?>
Please Help me to solve this Update Issue i am facing for a long time. I have researched all through but didn't got any solution.
Change your Save button type to "submit" and remove the <a> hyperlink.
Use <form> as a part of both modal-body and modal-footer so the submit button will be part of it.
Take book_id in a hidden field so it will be the part of POST.
Look at the modal code below:
<div id="editModal<?php echo $row['book_id']?>" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit This Book</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="updatebook.php" method="POST">
<input type="hidden" name="id" value="<?php echo $row['book_id'];?>">
<div class="modal-body">
<div class="form-group">
<label for="isbn" class="col-form-label">ISBN</label>
<input type="text" class="form-control" name="isbn" value="<?php echo $row['isbn'];?>">
</div>
<div class="form-group">
<label for="title" class="col-form-label">Enter Book Title</label>
<input type="text" class="form-control" name="title" value="<?php echo $row['title'];?>">
</div>
<div class="form-group">
<label for="author" class="col-form-label">Enter Author Name</label>
<input type="text" class="form-control" name="author" value="<?php echo $row['author'];?>">
</div>
<div class="form-group">
<label for="image" class="col-form-label">Image URL</label>
<input type="text" class="form-control" name="image" value="<?php echo $row['image'];?>">
</div>
<div class="form-group">
<label for="description" class="col-form-label">Enter Book Description</label>
<textarea class="form-control" name="description" value="<?php echo $row['description'];?>"></textarea>
</div>
<div class="form-group">
<label for="url" class="col-form-label">Book URL</label>
<input type="text" class="form-control" name="url" value="<?php echo $row['url'];?>"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="save">Save Changes</button>
</div>
</form>
</div>
</div>
</div>

Fancybox modal, can not populate input fields from database

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
});

Could not remove using parent div id in Jquery

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.

Modal not updating data on row 2 and so on

Hi so the modal works fine on the first row but when i clicked on the 2nd row modal doesnt fetch any data
The form where it fetches the data , this thing works on first page only or either no
$ID = $_POST['ID'];
$sql = "SELECT * FROM `unity_users` WHERE `uid` = '$ID'";
$res = mysqli_query($con,$sql);
if(mysqli_num_rows($res)>0){
$row = mysqli_fetch_assoc($res);
$htmlToReturn = '<form action="" enctype="multipart/form-data" class="formTopMargin" autocomplete="off" method="post">
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<div class="form-group">
<label for="cat">User Name:</label>
<input type="text" class="form-control" value="'.$row['name'].'" name = "name">
</div>
<div class="form-group">
<label for="cat">Email:</label>
<input type="email" class="form-control" value="'.$row['email'].'" name = "email">
</div>
<div class="form-group">
<label for="cat">Score:</label>
<input type="number" class="form-control" value="'.$row['score'].'" name = "score">
</div>
<div class="form-group">
<label for="cat">PPA:</label>
<input type="text" class="form-control" value="'.$row['ppa'].'" name = "ppa">
</div>
<div class="form-group">
<label for="cat">Hash:</label>
<input type="text" class="form-control" value="'.$row['hash'].'" name = "hash">
</div>
<div class="form-group">
<input type="hidden" hidden value="'.$row['uid'].'" name = "uid">
</div>
</div>
<div class="col-sm-3"></div>
</div>
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<button type="submit" name="update" class="btn loginButton">Update</button>
</div>
<div class="col-sm-3"></div>
</div>
</form>';
The Output of the code
<?php
$sql = "SELECT * FROM `unity_users`";
$res = mysqli_query($con,$sql);
if(mysqli_num_rows($res)>0){
while ($row = mysqli_fetch_assoc($res)) {
echo '<tr>';
echo '<td>'.$row['uid'].'</td>';
echo '<td>'.$row['name'].'</td>';
echo '<td>'.$row['email'].'</td>';
echo '<td>'.$row['score'].'</td>';
echo '<td>'.$row['ppa'].'</td>';
echo '<td>'.$row['hash'].'</td>';
if($row['payment']=="Released"){
$payment = "requested";
}else{
$payment = "pending";
}
echo '<td>'.$payment.'</td>';
echo '<td class="pointer"><i id="delete_'.$row['uid'].'" class="fa fa-trash fa-2x details" aria-hidden="true"></i></td>';
echo '<td class="pointer"><i data-toggle="modal" data-target="#myModal" id="edit_'.$row['uid'].'" class="fa fa-pencil-square-o fa-2x details" aria-hidden="true"></i></td>';
echo '</tr>';
}
}
?>
The modal
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 style="text-align: center;margin-top: 1%;font-size: 25px;" class="modal-title">User Data</h4>
</div>
<div class="modal-body" id="categoryModel">
</div>
</div>
</div>
First row which is working
Updating data is working
Page 2 second row not working

Php Private Message reply only functioning on the last row?

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.

Categories