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.
Related
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>
Without Modal, user_timeout.php does not have a problem but When I use modal, as you can see at the picture below the problem is. But they have same logic codes so I dont know what the problem is. I want to use modal for some quality design so help me guys thank you
logs.php
<a rel="tooltip" title="Timeout" id="<?php echo $idlogs; ?>" href="user_timeout.php<?php echo '?id='.$idlogs; ?>" class="btn btn-info"><i class="icon-minus icon-large"></i> Manual Time-Out</a>
And for Modal
<a rel="tooltip" title="timeout" id="<?php echo $idlogs; ?>" href="#timeout<?php echo $idlogs; ?>" data-toggle="modal" class="btn btn-success"><i class="icon-pencil icon-large"></i> Manual Time-Out</a>
<?php include('modal_time_user.php'); ?>
user_timeout.php
<?php $get_id= $_GET['id']; ?>
<div class="container">
<div class="margin-top">
<div class="row">
<div class="span12">
<?php
$query=mysqli_query($dbcon,"select * from user_logs_tbl where id ='$get_id'")or die(mysqli_error());
$row=mysqli_fetch_assoc($query);
$iduser=$row['user_id'];
$idlogs=$row['id'];
?>
<div class="alert alert-info"><i class="icon-pencil></i> Manual Time-out</div>
<p><a class="btn btn-info" href="logs.php"><i class="icon-arrow-left icon-large"></i> Back</a></p>
<div class="addstudent">
<div class="details">Please Enter Details Below</div>
<form class="form-horizontal" method="POST" enctype="multipart/form-data">
<div class="control-group">
<br>
<div class="control-group">
<label class="control-label" style="margin-left:10%;" for="inputEmail">Time-Out:</label>
<div class="controls">
<input type="time" id="inputEmail" name="timeout" placeholder="Time">
</div>
</div>
<br>
<div class="control-group">
<div class="controls">
<button name="timeouts" type="submit" style="margin-left:16%;" class="btn btn-success"><i class="icon-save icon-large"></i> Update</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
if (isset($_POST['timeouts'])){
$timeout=$_POST['timeout'];
$timeout = date('Y-m-d H:i:s', strtotime(str_replace('-', '/',
$timeout)));
mysqli_query($dbcon,"UPDATE user_logs_tbl set time_out = '$timeout' where id='$idlogs'")or die(mysqli_error($dbcon));
$yourURL="logs.php";
echo ("<script>location.href='$yourURL'</script>");
}
?>
But If I change it into modal form, it's working but all data will change if I change one
modal_time_user.php
<div id="timeout<?php echo $idlogs; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-body">
<div class="alert alert-info"><strong>Time</strong></div>
<form class="form-horizontal" method="post">
<div class="control-group">
<label class="control-label" for="inputEmail">Time-Out :</label>
<div class="controls">
<input type="time" id="inputEmail" name="time_out" pattern="[a-zA-Z0-9]{5,}" required>
</div>
</div>
<div class="control-group">
<div class="controls">
<button name="enter" type="submit" class="btn btn-success"><i class="icon-save icon-large"></i> Update</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove icon-large"></i> Close</button>
</div>
</div>
<?php
if (isset($_POST['enter'])){
$timeout=$_POST['time_out'];
$timeout = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $timeout)));
mysqli_query($dbcon,"UPDATE user_logs_tbl SET time_out='$timeout' where id = '$idlogs'")or die(mysqli_error($dbcon));
$yourURL="logs.php";
echo ("<script>location.href='$yourURL'</script>");
}
?>
Problem
After Inserting a Time Out In USER ID 45
When I update one of the user, It will update some of user's timein too.
It's updating but I don't know why the other user too.
If I edit the time out it will change the timeout too of the some users. Sorry for my bad english.
logs.php
<tbody>
<?php
$user_query=mysqli_query($dbcon,"SELECT * FROM user_logs_tbl where create_date >= date(now())")or die(mysqli_error($dbcon));
//$user_query=mysqli_query($dbcon,"SELECT * FROM user_logs_tbl")or die(mysqli_error($dbcon));
while($row=mysqli_fetch_array($user_query)){
$ids = isset($_row['id']) ? $_row['id'] : '';
$_SESSION=$id=$row['user_id'];
$user_query2=mysqli_query($dbcon,"SELECT * FROM users_tbl where id='$id'")or die(mysqli_error($dbcon));
$row2= mysqli_fetch_array($user_query2);?>
<tr class="del<?php echo $ids ?>">
<td>
<?php echo $row['id']; ?>
</td>
<td>
<?php echo $row2['firstname']." ".$row2['middlename']." ".$row2['lastname']; ?>
</td>
<td>
<?php $course= $row['create_date'];
if($course == '') {
echo "N/A";
} else {
echo $course;
}
?>
</td>
<td>
<?php echo $tayming=$row['time_in']; ?>
</td>
<td>
<?php $yr_lvl=$row['time_out'];
if($yr_lvl == '') {
?>
<a rel="tooltip" title="Timeout" id="<?php echo $id; ?>" href="#timeout<?php echo $id; ?>" data-toggle="modal" class="btn btn-info"><i class="icon-minus icon-large"></i> Manual Time-Out</a>
<?php include('modal_time_user.php');
} else {
echo $yr_lvl;
}
?>
</td>
<td>
<?php
$d=mktime(9, 06);
$nice=date("h:i", $d);
if($tayming >= $nice) {
echo "You're Late! Bro!";
} else {
echo "Very Good!";
}
?>
</td>
<td>
<a rel="tooltip" title="Edit" id="<?php echo $id; ?>" href="#edit<?php echo $id; ?>" data-toggle="modal" class="btn btn-success"><i class="icon-pencil icon-large"></i> Edit</a>
<?php include('modal_edit_time.php'); ?>
</td>
<?php include('toolttip_edit_delete.php'); ?>
</tr>
<?php } ?>
</tbody>
this is the modal where if you click the button edit
modal_edit_time.php
<div id="edit<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-body">
<div class="alert alert-info"><strong>Manual Time-In</strong></div>
<form class="form-horizontal" method="post">
<div class="control-group">
<label class="control-label" style="margin-left:29%;" for="inputEmail">Employee:</label>
<div class="controls">
<?php $wiw=mysqli_query($dbcon,"SELECT * FROM users_tbl where id='$id'");
$row2= mysqli_fetch_array($wiw);?>
<input type="hidden" id="inputEmail" name="id" value="<?php echo $row['user_id']; ?>" required>
<input type="text" name="userid" value="<?php echo $row2['firstname']." ".$row2['middlename']." ". $row2['lastname'];?>" readonly>
</div>
</div>
<div class="control-group">
<label class="control-label" style="margin-left:29%;" for="inputEmail">Date:</label>
<div class="controls">
<input type="date" id="inputEmail" value="<?php echo $row['create_date'];?>" name="create_date" placeholder="Date" required>
</div>
</div>
<div class="control-group">
<label class="control-label" style="margin-left:29%;" for="inputEmail">Time-In:</label>
<div class="controls">
<input type="time" id="inputEmail" value="<?php echo $row['time_in'];?>" name="timein" placeholder="Time" required>
</div>
</div>
<div class="control-group">
<label class="control-label" style="margin-left:29%;" for="inputEmail">Time-Out:</label>
<div class="controls">
<input type="time" id="inputEmail" value="<?php echo $row['time_out'];?>" name="timeout" placeholder="Time" required>
</div>
</div>
<div class="control-group">
<div class="controls">
<button name="edit" type="submit" class="btn btn-success"><i class="icon-save icon-large"></i> Save</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove icon-large"></i> Close</button>
</div>
</div>
<?php echo $id;
if (isset($_POST['edit'])){
$userid=$_POST['id'];
$timein=$_POST['timein'];
$timeout=$_POST['timeout'];
$create_date=$_POST['create_date'];
mysqli_query($dbcon,"UPDATE user_logs_tbl set time_in='$timein',time_out = '$timeout',create_date ='$create_date' where id='$id'")or die(mysqli_error($dbcon));
$yourURL="logs.php";
echo ("<script>location.href='$yourURL'</script>");
}
?>
Web interface:
Database :
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>
I can't make it work the short preview with LEFT() and substr() only with RIGHT() with mysql PDO but I need show the first 100 characters of description not the last ones...where is the error in my code?
Code:
<?php
$sql = $conn->prepare("SELECT id_blog, titulo, LEFT(blog,100) AS blog, DATE_FORMAT(f_blog, '%d %M %Y') AS f_blog FROM BLOG ORDER BY id_blog DESC");
$sql->execute();
while($row = $sql->fetch(PDO::FETCH_ASSOC)){ echo '
<div class="span9 pad15" id="'.$row["id_blog"].'">
<div class="row">
<div class="span1">
<div class="btn btn-medium btn-rounded btn-blog1">'; echo $row["f_blog"]; echo
'</div>
</div>
<div class="span8">
<h1 class="post_link">'; echo $row["blog_titulo"]; echo '</h1>
<p>'; echo $row["blog"]; echo ' ...</p>
<div class="read_more">Leer más →</div>
<div class="pad30"></div>
</div>
</div>
</div>'; } ?>
with LEFT(blog, 100) AS blog not show nothing
with substr(blog, 0,100) AS blog not show nothing
with RIGHT(blog,100) AS blog show the last 100 characters
Here the LEFT() is working nice in the same web page but in the first one no work.
CODE:
<?php
$sql = "SELECT id_oferta, oferta_titulo, oferta_subtitulo, LEFT(oferta_mensaje, 50) AS oferta_mensaje, oferta_precio, oferta_foto FROM OFERTAS ORDER BY id_oferta DESC";
$result = $conn->query($sql);
while($row = $result->fetch(PDO::FETCH_ASSOC)) { ?>
<?php if (!empty($row['id_oferta'])) { echo '
<div class="span3" id"'.$row["id_oferta"].'">
<div class="tile">
<div>
<img src="../admin/assets/img/ofertas/'.$row["oferta_foto"].'" alt="'.$row["oferta_titulo"].'" class="img-circle" style="max-width:100px; max-height:100px;" />
</div>
<span>'; echo $row["oferta_titulo"]; echo '</span>
<h6><small>'; echo $row["oferta_subtitulo"]; echo '</small></h6>
<p>'; echo $row["oferta_mensaje"]; echo '</p>
<h5><div class="intro-icon-disc"><b>$'; echo $row["oferta_precio"]; echo '</b></div></h5>
</div>
<div class="pad25"></div>
</div>'; } ?>
<div id="myModal" class="modal hide fade" id"<?php echo $row["id_oferta"]; ?>" 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"></button>
<h3 id="myModalLabel"><b>Cupón para : <?php echo $row["oferta_titulo"]; ?></b></h3>
</div>
<div class="modal-body">
<form name="cupon" id="cupon" method="post">
<div class="row-fluid grid">
<div class="span6">
<label><b>Nombres : </b></label><input type="text" class="input-block-level" name="nombres" />
</div>
<div class="span2">
</div>
<div class="span4">
<label><b>DUI : </b></label><input type="text" class="input-block-level" name="dui" />
</div>
</div>
<div class="row-fluid grid">
<div class="span6">
<label><b>Correo : </b></label><input type="text" class="input-block-level" name="corelectronico" />
</div>
</div>
<input type="hidden" name="of_titulo" type="text" value="<?php echo $row['oferta_titulo']; ?>" />
<input type="hidden" name="of_stitulo" type="text" value="<?php echo $row['oferta_subtitulo']; ?>" />
<input type="hidden" name="of_mensaje" type="text" value="<?php echo $row['oferta_mensaje']; ?>" />
<input type="hidden" name="of_precio" type="text" value="<?php echo $row['oferta_precio']; ?>" />
<input type="hidden" name="of_foto" type="text" value="<?php echo $row['oferta_foto']; ?>" />
<div class="row-fluid grid">
<div class="span4" id="div1">
<input type="hidden" name="action" value="create_cupon" />
<button class="positive btn btn-inverse" type="submit" id="enviar" name="enviar">
<i class="icon icon-save icon-white"></i>
Grabar Cupón
</button>
</div>
<div class="span4">
</div>
<div class="span4" id="div2">
<a class="negative btn btn-info" href="impcupon.php" target="popup" onClick="window.open(this.href, this.target, "scrollbars=yes,toolbar=no,menubar=no,status=no,width=parent,height=parent"); return false;" onclick="boton(this)" id="imprimir">
<i class=" icon-print icon-white"></i>
Imprimir Cupón
</a>
</div>
</div>
</form>
<div id="loading_cupon" style="display:none;"><img src="img/loaders/loader.gif" /></div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">
Cerrar
</button>
</div>
</div><?php } ?>
As mentioned in your comments oferta_mensaje is type longtext. You can use CAST() in this case.
"SELECT id_oferta, oferta_titulo, oferta_subtitulo,
CAST(oferta_mensaje as char(50))
AS oferta_mensaje, oferta_precio, oferta_foto
FROM OFERTAS ORDER BY id_oferta DESC";