テーブルのデータをクリック可能な行を介してモーダルのテキストボックスに渡そうとしています。データはすでにテーブルに表示されています。行をクリックすると、モーダルが表示されますが、テキストボックスは空白です。テーブルのデータはデータベースからのものでした。テーブルのデータをデータベースからモーダルに渡す
これはコードです:
PHPの:ここ
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name = "viewport" content = "width= device-width, initial-scale=1">
<link rel = "stylesheet" href = "bs/css/bootstrap.css">
<script src = "bs/js/jquery.min.js"></script>
<script src = "bs/js/bootstrap.min.js"></script>
<meta charset="utf-8">
</head>
<body>
<div class="container">
<div class="header">
<?php include("header.php"); ?>
</div>
<div class = "navigation">
<?php include("navigator.php"); ?>
</div>
</div>
<center>
<style>
table tr:not(:first-child){
cursor: pointer;
}
table tr:not(:first-child)hover{
background-color:azure;
color:black;
}
</style>
<?php
include("dbConfig.php");
$result = mysqli_query ($con, "SELECT * FROM information");
echo "<table id=table border = 1 width = 50%>
<tr>
<th align = center> Control # </th>
<th> Last Name </th>
<th> First Name </th>
<th> Contact Number </th>
</tr>";
while($row=mysqli_fetch_array($result)){
echo "<form action = method =post>";
echo "<tr data-toggle=modal data-target=#fmodal name = pass type = submit>";
echo "<td id='cn'>".$row['Control_Number']. "</td>";
echo "<td>".$row['Last_Name']. "</td>";
echo "<td>".$row['First_Name']. "</td>";
echo "<td>".$row['Contact_Number']. "</td>";
echo "</tr>";
echo "</form>";
}
echo "</table>";
if(isset($_POST['submit'])){
$res = mysqli_query($con, "SELECT * FROM information WHERE Control_Number=$_POST[cn]");
while($rowval = mysqli_fetch_array($res)){
$controlnumber= $rowval['Control_Number'];
$lastname= $rowval['Last_Name'];
$firstname= $rowval['First_Name'];
$contactnumber= $rowval['Contact_Number'];
}
}
?>
<div class = "modal fade" id = "fmodal" role = "dialog">
<div class = "modal-dialog" role = "document">
<div class = "modal-content">
<div class = "modal-header">
<button type = "button" class = "close" data-dismiss = "modal">×</button>
<h4>FORM</h4>
</div>
<div class = "modal-body text-center">
<label>Control Number:</label>
<input class = "input-lg" type = "text" id = "Control_Number" value = '<?php echo $controlnumber; ?>'><br>
<label>Last Name:</label>
<input class = "input-lg" type = "text" id = "Last_Name" value = '<?php echo $lastname; ?>'><br>
<label>First Name:</label>
<input class = "input-lg" type = "text" id = "First_Name" value = '<?php echo $firstname; ?>'><br>
<label>Contact Number:</label>
<input class = "input-lg" type = "text" id = "Contact_Number" value = '<?php echo $contactnumber; ?>'><br>
</div>
</div>
</div>
</div>
</center>
</body>
まず、http://bobby-tables.comを見てみましょうSQLインジェクションのリスクは非常に高いです。あなたのクエリには準備された文を使用し、ユーザの入力を直接クエリに入れないでください!あなたの問題について:まず、 '$ controlnumber =" ";のようなループの外側の変数を定義します - PHPで変数のスコープについての詳細を知りたい場合は' PHP while loop scope'を探します。 – Twinfriends
@MYxx私はあなたの質問を理解しているので、送信ボタンをクリックするとテーブルデータが表示され、モーダルがポップアップしなければならず、特定の値をテーブルに表示する必要があります。しかし、これはあなたに私たちに 'AJAX'が必要です。 –
ここで@MYxxは、 'php' 'mysql' 'ajax' 'jquery'と似た例です。このリンクをクリックして、あなたが探しているものか、必要なものかを教えてください。私はもっともっと追加する必要があります.. [link 1](https://ibb.co/n4N0fF)[link 2](https://ibb.co/kXYj7v) –