short preview with mysql pdo - php

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";

Related

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

Affecting all data in Database While Using Modal

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

Datetimepicker in form not transferring date

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>

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.

Undefined index: template_id

I am karthik, in my project i have one problem, i am getting error undefine index: template_id. I have searched more in net but i can't rectify this problem i have attached my code below, please guide me
if($fetquery["template_id"] == 5){
$query = mysql_query("SELECT * FROM ".$fetquery['table_name']." WHERE template_content_id = ".$fetquery['id']."");
$fetquery = mysql_fetch_array($query);
?>
<!-- Template5-->
<input type="hidden" name="template5" value="template5">
<div class="fillContent" id="subscreen5">
<div class="mainTitle">
<h3>Fill Content - Template E</h3>
</div>
<input type="hidden" name="template5id" value="<?php echo $fetquery['temp5_id']; ?>">
<div class="current-title">
<label>Main Title</label> <input type="text" class="fillTitleText" name="etemp5title"placeholder="Lorem Ipsum" value="<?php echo $fetquery['title']; ?>"><!-- Edit -->
</div>
<div class="section2">
<div class="contentSecTitle">
<h3>Banner Image</h3>
</div>
<div class="subSec">
<div class="subSec1">
<div class="contentSec2Left">
<input type="text" id="template5banner" value="<?php echo $fetquery['bannerimage']; ?>" class="upLoadText">
<div class="fileUpload btn btn-primary">
<span class="uploadImage"></span>
<input id="temp5_bannerimg" onchange="addtemplate5banner(this)" name="etemplate5bannerimg" type="file" class="upload" value="Browse">
</div>
</div>
<div class="contentSecRight">
<input type="hidden" name="gettopImage" value="<?php echo $fetquery['bannerimage']; ?>">
<p class="imageView3"><img src="<?php echo $fetquery['bannerimage']; ?>" style="width:82px; height:82px;" id="changetemp5banner"><br><br>Current Image</p>
<!-- <p class="imageView4">filename.jpg</p>
<div class="deLete">
</div>
-->
</div>
</div>
</div>
</div>
<div class="fillSec">
<div class="contentSecTitle">
<h3>Content</h3>
</div>
<div class="current-textarea">
<div class="text-area">
<label>Description</label> <textarea rows="4" name="etemp5desc" ><?php echo $fetquery['description']; ?></textarea>
</div>
</div>
</div>
</div>
<?php
}
if($fetquery["template_id"] == 6){
//echo "SELECT * FROM ".$fetquery['table_name']." WHERE template_content_id = ".$fetquery['id']."";
$query = mysql_query("SELECT * FROM ".$fetquery['table_name']." WHERE template_content_id = ".$fetquery['id']."");
$fetquery = mysql_fetch_array($query);
?>
<!-- Template6-->
<input type="hidden" name="template6" value="template6">
<div class="fillContent" id="subscreen6">
<div class="mainTitle">
<h3>Fill Content - Template F</h3>
</div>
<input type="hidden" name="template6id" value="<?php echo $fetquery['temp6_id']; ?>">
<div class="current-title">
<label>Main Title</label> <input value="<?php echo $fetquery['title']; ?>" type="text" class="fillTitleText" name="etemplate6title" placeholder="Lorem Ipsum"> <!--Edit -->
</div>
<div class="section2">
<div class="contentSecTitle">
<h3>Banner Image</h3>
</div>
<div class="subSec">
<div class="subSec1">
<div class="contentSec2Left">
<input type="text" id="template6banner" value="<?php echo $fetquery['bannerimage']; ?>" class="upLoadText">
<div class="fileUpload btn btn-primary">
<span class="uploadImage"></span>
<input id="temp6_bannerimg" onchange="addtemplate6banner(this)" name="template6bannerimg" type="file" class="upload" value="Browse">
</div>
</div>
<div class="contentSecRight">
<input type="hidden" name="gettopImage" value="<?php echo $fetquery['bannerimage']; ?>">
<p class="imageView3"><img src="<?php echo $fetquery['bannerimage']; ?>" style="width:82px; height:82px;" id="changetemp6banner"><br><br>Current Image</p>
<!-- <p class="imageView4">filename.jpg</p>
<div class="deLete">
</div> -->
</div>
</div>
</div>
</div>
<div class="fillSec">
<div class="contentSecTitle">
<h3>Content</h3>
</div>
<div class="current-textarea">
<div class="text-area">
<label>Desription</label> <textarea rows="4" name="temp6desc"><?php echo $fetquery['description']; ?></textarea>
</div>
</div>
</div>
</div>
<?php } ?>
This code was in ajax page
Try to add a check before using it. And also check if it is defined or not. -
if (!empty($fetquery["template_id"]) && $fetquery["template_id"] == 5) { ...

Categories