Echo HTML tag problems with quotes - php

I am trying to put quotes in the php that handles the select tag. I need that the select tag displays the result of the query that is inside. How can I do this correctly?
<?php
$sql1 = mysql_query("SELECT * FROM `metlab`.`cutlog_junta` WHERE `finalizado` = 0")or die (mysql_error());
$idtimeleft= 0;
while($array = mysql_fetch_array($sql1, MYSQL_BOTH)){
$idtimeleft++;
$idprueba = $array[0];
$id_log = $array["id_log"];
$id_operador = $array["id_operador"];
$started = $array["started"];
$finished = $array["finished"];
date_default_timezone_set("America/Mexico_City");
$tiempo1 = new DateTime('now');
$tiempo2 = new DateTime($finished);
if ($tiempo1 < $tiempo2){
$tiemporestante = date_diff($tiempo2,$tiempo1 );
$timeleft = $tiemporestante->format("%h:%i:%s");
}else{
$timeleft = "00:00:00";
}
$sql = mysql_query("SELECT r.job AS JOB,p.heat_code AS HEAT_CODE,p.probeta AS PROBETA,p.id_line AS ID_LINE,p.id_box_pin AS ID_BOX_PIN,p.id_conexion AS ID_CONEXION
FROM metlab.prueba_junta p
INNER JOIN metlab.requerimientos_junta r ON p.id_job=r.id WHERE p.id='".$id_log."'")or die (mysql_error());
$mhs = mysql_fetch_array($sql);
echo (" <tr id='row". $idtimeleft ."'>
<td><input type='checkbox' name='record'></td>
<td>" . $id_log . "</td>
<td>" . $mhs['JOB'] . "</td>
<td>" . $mhs['ID_BOX_PIN'] . "</td>
<td>" . $mhs['ID_CONEXION'] . "</td>
<td>" . $mhs['HEAT_CODE'] . "</td>
<td>" . $mhs['PROBETA'] . "</td>
<td>" . $mhs['ID_LINE'] . "</td>
<td>" . $started . "</td>
<td><div id='idtimeleft" . $idtimeleft ."'>" . $timeleft . "</div></td>
<td><button type='button' class='btn btn-primary' data-toggle='modal' data-target='#cut_process'><i class='fa fa-cog fa-spin'></i>CUT</button>
<div id='cut_process' class='modal fade' role='dialog'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button'class='close' data-dismiss='modal'>×</button>
<h4 class='modal-title'>CUT PROCESS</h4>
</div>
<div class='modal-body'>
<input type='text' placeholder='INSERT COMMENT' class='form-control'><br>
<label>Supervisor:</label>
<select class='btn btn-primary'>
<?php //////////////////////////////problem
$query='SELECT nombre
FROM metlab.supervisores';
$result1=mysql_query($query);
while($row1=mysql_fetch_array($result1)):;?>
<option><?php echo $row1[0];?>
</option>
<?php endwhile;?>
</select> /////////////////////////////end problem
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-success' data-dismiss='modal'><i class='fa fa-paper-plane'></i>SEND COMMENT</button>
</div>
</div>
</div>
</div>
</td>
<td>
<button type='button' class='btn btn-warning' data-toggle='modal' data-target='#milling_process'><i class='fa fa-cog fa-spin'></i>MILLING</button>
<div id='milling_process' class='modal fade' role='dialog'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button'class='close' data-dismiss='modal'>×</button>
<h4 class='modal-title'>MILLING PROCESS</h4>
</div>
<div class='modal-body'>
<input type='text' placeholder='INSERT COMMENT' class='form-control'>
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-success' data-dismiss='modal'><i class='fa fa-paper-plane'></i>SEND COMMENT</button>
</div>
</div>
</div>
</div>
</td>
<td>
<button type='button' class='btn btn-success' data-toggle='modal' data-target='#rectified_process'><i class='fa fa-cog fa-spin'></i>RECTIFIED</button>
<div id='rectified_process' class='modal fade' role='dialog'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button'class='close' data-dismiss='modal'>×</button>
<h4 class='modal-title'>RECTIFIED PROCESS</h4>
</div>
<div class='modal-body'>
<input type='text' placeholder='INSERT COMMENT' class='form-control'>
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-success' data-dismiss='modal'><i class='fa fa-paper-plane'></i>SEND COMMENT</button>
</div>
</div>
</div>
</div>
</td>
<td>
<button type='button' class='btn btn-danger' data-toggle='modal' data-target='#machined_process'><i class='fa fa-cog fa-spin'></i>MACHINED</button>
<div id='machined_process' class='modal fade' role='dialog'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button'class='close' data-dismiss='modal'>×</button>
<h4 class='modal-title'>MACHINED PROCESS</h4>
</div>
<div class='modal-body'>
<input type='text' placeholder='INSERT COMMENT' class='form-control'>
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-success' data-dismiss='modal'><i class='fa fa-paper-plane'></i>SEND COMMENT</button>
</div>
</div>
</div>
</div>
</td>
<td>" . $finished . "</td>
<td>" . $idprueba . "</td>
</tr>");
}
?>

I think you should write directly HTML code inside the page avoiding PHP echo function.
In this example you use PHP short tag only when you need it:
<tr id="row<?=$idtimeleft?>">
And when you need to perform some action you just open PHP tag and write your code.
<select>
<?php
$query='SELECT nombre FROM metlab.supervisores';
$result1=mysql_query($query);
while($row1=mysql_fetch_array($result1)):
?>
<option><?=$row1[0]?></option>
<?php endwhile;?>
</select>
You don't need semicolon after "while(...):"
Anyway you should read something about Twig to use template engine to write cleaner code.
Bye!!

Related

How to Make delete confirmation modal using PHP

When I click the delete button I want to make a confirmation on a Bootstrap modal, before the user can delete it. The problem is that i don't know how to passed the $muestra['id'] from the data table to my modal.
<?php
$busqueda=$conn->query("select * from productos");
$arrDatos=$busqueda->fetchAll(PDO::FETCH_ASSOC);
foreach ($arrDatos as $muestra) {
echo "<tr>
<td>" . $muestra['id'] . "</td>
<td>" . $muestra['nombre'] . "</td>
<td>" . $muestra['unidades'] . "</td>
<td>
<a href='del.php?id=".$muestra['id']."' class='btn btn-danger' data-bs-toggle='modal' data-bs-target='#deleteModal'>
<ion-icon name='trash-outline'></ion-icon>
</a>
</td>
</tr>
<!-- Modal -->
<div class='modal fade' id='deleteModal' tabindex='-1' aria-labelledby='deleteModalLabel' aria-hidden='true'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-header'>
<h1 class='modal-title fs-5' id='deleteModalLabel'>¿Estás seguro de que quieres borrar el elemento?</h1>
<button type='button' class='btn-close' data-bs-dismiss='modal' aria-label='Close'></button>
</div>
<div class='modal-body'>
¿Estás seguro de que quieres borrar el elemento?
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-secondary' data-bs-dismiss='modal'>No</button>
<a href='del.php?id=".$muestra['id']."' class='btn btn-danger'>Sí</a>
</div>
</div>
</div>
</div>
<!-- End Modal -->
";
}
?>
</table>
I've tried many things, I know it's a simple problem, I've searched in old answers, but I'm new to coding and I can't solve the problem.
There will be need of some JS since that is done on the browser side. Using JS you get the id attribute of the modal when the button is click and do your logic.

CRUD delete using modal form

I am creating a CRUD using PHP extension with PDO, and I want to create a confirmation for registry deletion using Bootstrap modals, but I don't know how I can pass the ID information to the modal to delete, how can I do it?
index.php
<tbody>
<?php
$pdo = DB::connect();
$stmt = $pdo->query("SELECT * FROM people");
while ($row = $stmt->fetch()) {
echo "<tr>";
echo "<th scope='row'>" . $row["id"] . "</th>";
echo "<td>" . $row["first_name"] . "</td>";
echo "<td>" . $row["last_name"] . "</td>";
echo "<td>" . $row["notes"] . "</td>";
if ($row["allowed"]) {
echo "<td>" . "✔" . "</td>";
} else {
echo "<td>" . "✗" . "</td>";
};
echo "<td>";
// modal trigger
echo "<button type=\"button\" class=\"btn btn-danger\" data-toggle=\"modal\" data-target=\"#exampleModal\">Delete</button>";
echo "</td>";
echo "</tr>";
}
?>
</tbody>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Do you want to delete this registry?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger">Yes</button>
</div>
</div>
</div>
</div>
In this section add your ID
echo "<button type='button' class='btn btn-danger' data-toggle='modal' data-target='#exampleModal' onclick='$(".delete_id").val('".$row["id"]."')'>Delete</button>";
Then in modal add an hidden input field like so:
<input type="hidden" name="delete_id" class="delete_id">
Include jQuery before this function. You also need to have a delete file to pass that variable. After the request was success you could re-render the HTML.
function deleteRecord() {
var id = $(".delete_id").val();
$.ajax({
url:"/delete.php",
method:"POST",
data:{
id: id,
},
success:function(response) {
},
});
}
After we have stored the value of the ID we can delete it
<button type="submit" class="btn btn-danger" onclick="deleteRecord()">Yes</button>
Hope this was helpful

Show all rows on PHP/sql

I'm doing a small app. The thing is that when I'm running it, it will only show 300 rows when I should have around 2000 that I inserted for the test. It just doesn't shows them. It shows 312 rows, and not the rest.
Here is the code:
<!-- page content -->
<div class="right_col" role="main">
<div class="page-title">
<div class="title_left">
<h3>Raw Inventory</h3>
</div>
<div class="title_right">
<div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Go!</button>
</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Assets List</h2>
<ul class="nav navbar-right panel_toolbox">
<li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
</li>
<li><a class="close-link"><i class="fa fa-close"></i></a>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="x_content">
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header clearfix">
<h2 class="pull-left"></h2>
Add a new Asset
</div>
<?php
// Include config file
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM t_assets";
if($result = mysqli_query($db, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>Asset</th>";
echo "<th>Model</th>";
echo "<th>Status</th>";
echo "<th>Location</th>";
echo "<th>Action</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . ucfirst ($row['a_asset']) . "</td>";
echo "<td>" . $row['a_model'] . "</td>";
echo "<td>" . ucfirst($row['a_status']) . "</td>";
echo "<td>" . ucfirst($row['a_location']) . "</td>";
echo "<td>";
echo "<a href='read.php?id=". $row['a_asset'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>  ";
echo "<a href='update.php?id=". $row['a_asset'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>  ";
echo "<a href='delete.php?id=". $row['a_asset'] ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($db);
}
// Close connection
mysqli_close($db);
?>
</div>
</div>
</div>
</div>
</body>
</html> </div>
</div>
</div>
</div>
</div>
</div>
Any idea what I can do about this?
This is really my only problem, and I just need to add more text right now.
Or well, if you guys want to give me tips to make a global search function that would also be nice. Like, being able to search for information on all columns. Though I'm quite sure that It's not that hard.
I wonder... I need to investigate how to sort the results by name or creation date too.
Thanks, everyone!

Update & delete MySQL from modal bootstrap

I´m trying to delete and/or update data from form inside a modal window .For create it I haven´t problem but with the others actions (delete and update) I always have a problem,I think the key is the "id" it seems take the last value and not the value that I want to delete or update.
I know my code could be more nice.
<div class="container">
<div class="row espacio">
<p class="col-md-1"><a data-toggle="modal" href="#myModal" class="btn btn-default glyphicon glyphicon-plus"><span></span></a></p>
<p class="col-md-1 col-md-offset-10"><span class="btn btn-default glyphicon glyphicon-envelope"></span></p>
<table class="table table-bordered">
<caption>Bitácora</caption>
<thead>
<tr>
<th>Tecnico</th>
<th>Turno</th>
<th>Información</th>
<th>Estado</th>
<th>Creada</th>
<th>Modificada</th>
</tr>
</thead>
<tbody>
<?php
$txt ="";
$nombres =array();
$turnos = array('Mañana','Tarde','Noche');
$estados =array('Pendiente','Cerrado');
$db = new Db;
$sql = "SELECT * FROM tecnicos";
foreach ($db->consulta($sql) as $row) {
array_push($nombres,$row['Nombre']);
}
$sql = 'SELECT * FROM bitacora ORDER BY Estado DESC';
$consulta = $db->consulta($sql);
while ($row = mysqli_fetch_array($consulta)) {
$tecnico = $turno = $estado = "";
if ($row['Estado'] == "Pendiente"){
$txt .= "<tr class= 'bg-warning'>";
}else{
$txt .= "<tr class= 'bg-success'>";
}
$txt .= "
<td>". $row['Name'] . "</td>
<td>". $row['Turno'] . "</td>
<td>". $row['Info'] . "</td>
<td>". $row['Estado'] . "</td>
<td>". $row['RecordDate'] . "</td>
<td>". $row['ModiDate'] . "</td>
<td class='text-center'><a data-toggle='modal' href='#myModalUpdate".$row['Id']."''><span class='glyphicon glyphicon-pencil'></span></a>
<a data-toggle='modal' href='#myModalDelete".$row['Id']."''><span class='glyphicon glyphicon-remove'></span></a> </td>
</tr>";
//MODAL UPDATE
for ($i=0; $i <sizeof($nombres) ; $i++) {
if ($nombres[$i] == $row['Name'] ) {
$tecnico .= '<option value="'.$nombres[$i].'" selected="selected">'.$nombres[$i].'</option>';
}
else{
$tecnico .= '<option value="'.$nombres[$i].'" >'.$nombres[$i].'</option>';
}
}
for ($i=0; $i <sizeof($turnos) ; $i++) {
if ($turnos[$i] == $row['Turno']) {
$turno .= '<option value="'.$turnos[$i].'" selected="selected">'.$turnos[$i].'</option>';
}
else{
$turno .= '<option value="'.$turnos[$i].'" >'.$turnos[$i].'</option>';
}
}
for ($i=0; $i <sizeof($estados) ; $i++) {
if ($estados[$i] == $row['Estado']) {
$estado .= '<option value="'.$estados[$i].'" selected="selected">'.$estados[$i].'</option>';
}
else{
$estado .= '<option value="'.$estados[$i].'" >'.$estados[$i].'</option>';
}
}
$txt .= " <div class='modal fade' id='myModalUpdate".$row['Id']."' 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'>Modifica registro en Bitácora</h4>
</div>
<div class='modal-body'>
<form role='form' action='' method='post'>
<div class='form-group'>
<input type='text' name='id' value='".$row['Id']."'>
</div>
<div class='form-group'>
<label>Técnico</label>
<select class='form-control' name='modnombre'>
".$tecnico."
</select>
</div>
<div class='form-group'>
<label>Turno</label>
<select class='form-control' name='modturno'>
".$turno."
</select>
</div>
<div class='form-group'>
<label>Información</label>
<textarea class='form-control' name='modinformacion'>".$row['Info']."</textarea>
</div>
<div class='form-group'>
<label>Estado</label>
<select class='form-control' name='modestado'>
".$estado."
</select>
</div>
<div class='form-group text-center'>
<button type='submit' class='btn btn-warning' name='actualizar'>Actualiza</button>
</div>
</div><!--/modal body-->
<div class='modal-footer'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
</div>
</div><!--/modal content-->
</div><!--/modal dialog-->
</div><!--/modal-->";
//MODAL DELETE
$txt .= " <div class='modal fade' id='myModalDelete".$row['Id']."' 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'>Elemina registro en Bitácora</h4>
</div>
<div class='modal-body'>
<form role='form' action='' method='post'>
<div class='form-group'>
<input type='text' name='id' value='".$row['Id']."'>
</div>
<div class='form-group text-center'>
<button type='submit' class='btn btn-danger' name='eliminar'>Elimina</button>
</div>
</div><!--/modal body-->
<div class='modal-footer'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
</div>
</div><!--/modal content-->
</div><!--/modal dialog-->
</div><!--/modal-->";
}//end for principal
echo $txt;
?>
</tbody>
</table>
</div>
<!--MODAL CREATE-->
<div class="modal fade" id="myModal" 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">Añade registro en Bitácora</h4>
</div>
<div class="modal-body">
<form role="form" action="" method="post">
<div class="form-group">
<label>Técnico</label>
<select class="form-control" name="nombre">
<?php
$txt ="";
$db = new Db;
$sql = "SELECT * FROM tecnicos";
foreach ($db->consulta($sql) as $row) {
$txt.= "<option value='".$row['Nombre']."'>".$row['Nombre']."</option>";
}
echo $txt;
?>
</select>
</div>
<div class="form-group">
<label>Turno</label>
<select class="form-control" name="turno">
<option value="Mañana">Mañana</option>
<option value="Tarde">Tarde</option>
<option value="Noche">Noche</option>
</select>
</div>
<div class="form-group">
<label>Información</label>
<textarea class="form-control" name="informacion"></textarea>
</div>
<div class="form-group text-center">
<button type="submit" class="btn btn-success" name="crear">Crear</button>
</div>
</form>
</div><!--/modal body-->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!--/modal content-->
</div><!--/modal dialog-->
</div><!--/modal-->
</div> <!-- /container -->
And these are the action´s form
enter code //formulario CREATE
if(isset($_POST["crear"])) {
$nombre = $_POST["nombre"];
$turno = $_POST["turno"];
$informacion = $_POST["informacion"];
$sql = "INSERT INTO bitacora (Name,Turno,Info,Estado,RecordDate,ModiDate) VALUES ('" . $nombre . "', '" . $turno . "', '" . $informacion . "','Pendiente',now(),now())";
$db->consulta($sql);
}
//formulario UPDATE
if(isset($_POST["actualizar"])) {
$sql = "UPDATE bitacora SET Name = '" . $_POST["modnombre"] . "', Turno = '" . $_POST["modturno"] . "', Info = '" .$_POST["modinformacion"]. "', Estado = '" . $_POST["modestado"] . "' , ModiDate =now() WHERE Id = '".$_POST["id"]."' ";
$db->consulta($sql);
}
//form DELETE
if(isset($_POST["eliminar"])) {
$id = $_POST["id"];
$sql = "DELETE FROM bitacora WHERE Id = $id";
$db->consulta($sql);
}here
It seems that your input named "id" is not taking the correct value of $row['Id']. Try to inspect it and see if his "value" is not empty.
If the value was empty, your problem is the value of $row['Id'].
Try to replace $row['Id'] by $row['id'] and see the results.

Twitter Bootstrap Modal Dialog not working well.

Good day, I am displaying members of a team each on a DIV. For each DIV, there is a message button for a user to send message. The message button fires up a Bootstrap modal dialog box where one can type the message. Now, my problem is that I want the name of person the message is being sent to, to appear at the top of the dialog box but it is not working. It only shows the name of the first person in the database even when I click on the third person.
<?php
require_once "include/db_handle.php";
$sql = "SELECT i.*, m.* FROM addclique i JOIN members m ON m.id = i.clique_id WHERE adder_id = :id";
foreach ($db->query($sql, array('id' => $_SESSION['id'])) AS $result)
{
echo "
<div class='user_container'>
Name: </span> {$result['surname']} {$result['firstname']}</br>
<a href='test.php' class='' data-toggle='modal' data-target='#basicModal'>Send Message</a>
</div>
<div class='modal fade' id='basicModal' tabindex='-1' role='dialog' aria-labelledby='basicModal' aria-hidden='true'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
<h4 class='modal-title points' id='myModalLabel'><span style ='color:black;'>To:</span> {$result['firstname']} </h4>
</div>
<div class='modal-body'>
<form action='send.php' method='POST'>
<textarea name='message' rows='10' cols='65'></textarea></br>
</form>
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
<button type='button' class='btn btn-primary' data-dismiss='modal'>Send Message</button>
</div>
</div>
</div>
</div>
</div>";
}
?>
<a href='test.php' class='' data-toggle='modal' data-target='#**basicModal**'>Send Message</a>
<div class='modal fade' id='**basicModal**' tabindex='-1' role='dialog' aria-labelledby='basicModal' aria-hidden='true'>
If you really want to do a modal for each user, consider do a variable for your modals.
Not sure, but something like that.
var $counter = 0;
foreach ($db->query($sql, array('id' => $_SESSION['id'])) AS $result)
{
echo "
<div class='user_container'>
Name: </span> {$result['surname']} {$result['firstname']}</br>
<a href='test.php' class='' data-toggle='modal' data-target='#basicModal".<?= $counter ?>." '>Send Message</a>
</div>
<div class='modal fade' id='basicModal".<?= $counter ?>."' tabindex='-1' role='dialog' aria-labelledby='basicModal' aria-hidden='true'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
<h4 class='modal-title points' id='myModalLabel'><span style ='color:black;'>To:</span> {$result['firstname']} </h4>
</div>
<div class='modal-body'>
<form action='send.php' method='POST'>
<textarea name='message' rows='10' cols='65'></textarea></br>
</form>
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
<button type='button' class='btn btn-primary' data-dismiss='modal'>Send Message</button>
</div>
</div>
</div>
</div>
</div>";
$counter++;
}
?>
You are creating modal for each user with same id i.e. basicModal. So if total user is 5 then 5 modal with same id is created on html page.
<a data-toggle='modal' data-target="#basicModal">Show Modal</a>
And in the above link you are calling #basicModal.So the js cant find the that particular user modal id because it is not unique.So it display the first modal with that id(or display none)
The problem should be solved if you use unique id in the link and modal .But a better option would be creating a single modal and setting the data through js so that multiple modal html is not placed in page.If you want to do it with jquery
Send Message
In jquery
$("#showModal").on("click",function(){
//set modal data
});

Categories