无法使用数据库中的php检索数据到Bootstrap模式,单击以编辑和删除页面和数据库

时间:2017-04-10 10:54:43

标签: php html database mysqli

<div class="container">
<h2>Modal  Example</h2>
 <!-- Trigger the modal with a button -->

<button type="button" class="btn btn-primary btn-xs" id="myBtn">View  All</button>

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">

  <!-- Modal content-->
<div class="modal-content">
<div class="modal-header" style="padding:5px 5px;">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h5> Employee details </h5>
</div>
<div class="modal-body" style="padding:40px 50px;">
<table width="100%" border="1" >
<tr> 
    <td><strong><font color="#000000">ID</font></strong></td>
    <td><strong><font color="#000000">fileno</font></strong></td>
    <td><strong><font color="#000000">gender</font></strong></td>
    <td><strong><font color="#000000">comments</font></strong></td>

<td><strong><font color="#000000">Edit|Delete</font></strong></td>
    </tr>


<?PHP
error_reporting(E_ALL); //cehck all errors
ini_set('display_errors',1); //display those errors
$connect = mysqli_connect('localhost','root','','radio') or die (mysqli_connect_error());
if(!$connect) die("Unable to connect to MySQL").mysqli_error($connect);

//mysqli_select_db($connect,"radio_table") or die ("no database"); Select database 

$sql = "SELECT Id,fileno,gender,comments FROM `radio_table` WHERE  vehicle2 = 'Car'";
echo "query".$sql;


//echo $sql;exit;
$result = mysqli_query($connect,$sql);
echo "problem occur".mysqli_error($connect);
while($row=mysqli_fetch_array($result))


  {
  ?>
    <tr> 
      <td><?php echo $row['Id']; ?></td>
      <td><?php echo $row['fileno']; ?></td>
      <td><?php echo $row['gender']; ?></td>
      <td><?php echo $row['comments']; ?></td> 
      <td><a href="addradiosql.html?cid=<?php echo $row['Id']; ?>"><strong>Edit</strong></a> | <a href="addradiosql.html?action=delete&id=<?php echo $row['Id']; ?>"><strong>Delete</strong></a></td>
    </tr>
    </table>
    </div>
  <?php
  }
  mysqli_close($connect);
  ?>
      <div class="modal-footer">
        <button type="submit" class="btn btn-danger btn-default pull-right" 
     data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> 
     Cancel</button>
    </div>
    </div>

    </div>
    </div> 
    </div>

<script>
$(document).ready(function(){
$("#myBtn").click(function(){
    $("#myModal").modal();
 });
 });
</script>

1)我无法使用php,mysql从数据库检索所选数据。

2)当点击特定个人表格的ID时,应显示特定员工的填写详细信息

3)当点击特定Id的编辑或删除时a)编辑表单页面包含允许编辑的填充详细信息或b)删除 - 删除数据库中的所有详细信息。

我是否有一个如何做到这一点的小例子? NOTE Before Marking As Duplicate:我搜索了许多其他链接,但没有一个工作。

2 个答案:

答案 0 :(得分:0)

将脚本代码更改为:

<script>
$(document).ready(function(){
$("#myBtn").click(function(){
    $("#myModal").modal('show');
 });
 });
</script>

答案 1 :(得分:0)

以下代码显示表格中的所有数据

retreive.html

&#13;
&#13;
<!DOCTYPE html>
<html>
<body>

 <form action="Table.html" enctype="multipart/form-data" method="post">
  First name:<br>
  <input type="text" name="firstname" value="">
  <br>
  Last name:<br>
  <input type="text" name="lastname" value="">
  <br><br>
  <input type="submit" value="Submit">
</form> 



</body>
</html>
&#13;
&#13;
&#13;

Table.html

&#13;
&#13;
<!DOCTYPE html>
<html>
<head> 
	<link rel="stylesheet" href="css/bootstrap.min.css">
	<link rel="stylesheet" href="customstyle.css">
	
</head>
<body>
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
	<!--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>-->
	<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
	
	<div class="container">
	<table width="100%" border="1" >
        <tr> 
          <td><strong><font color="#000000">ID</font></strong></td>
          <td><strong><font color="#000000">firstname</font></strong></td>
          <td><strong><font color="#000000">lastname</font></strong></td>
          
          
    <td><strong><font color="#000000">Edit|Delete</font></strong></td>
        </tr>
	<?php 
    include "sql.php";
	?>
		
	
	</table>
	</div>
</body>
</html>
&#13;
&#13;
&#13;

数据库连接db.php

<?php

    $connect = mysqli_connect('localhost','root','','radio') or die (mysqli_connect_error());
    if(!$connect) die("Unable to connect to MySQL").mysqli_error($connect);

?>

sql.php

<?php 
include "db.php";

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];

  $query = "INSERT INTO `sql_re_up`(firstname,lastname) VALUES('$firstname','$lastname')";
  if(mysqli_query($connect,$query)){ //check query executed or not
        echo 'inserted' . '<br>' ;
  }

  /*
 $sql = "SELECT firstname,lastname   FROM sql_re_up ";
  $result = mysqli_query($connect,$sql); //check query executed or not
      while($row=mysqli_fetch_array($result))
    {

     echo $row['firstname']; 
     echo $row['lastname']; 

    }
*/
/*
 $sql = "SELECT firstname,lastname   FROM sql_re_up WHERE Id='26';";
  $result = mysqli_query($connect,$sql); //check query executed or not
      while($row=mysqli_fetch_array($result))
    {

     echo $row['firstname']; 

     echo $row['lastname']; 

    }
*/

 /* $sql = "SELECT firstname,lastname,Id   FROM sql_re_up WHERE firstname='eiman'";
  $result = mysqli_query($connect,$sql); //check query executed or not
      while($row=mysqli_fetch_array($result))
    {
        echo $row['Id'] . '<br>' ;
     echo $row['firstname'] . '<br>' ; 

     echo $row['lastname'] . '<br>' ;



    }*/



    $sql = "SELECT firstname,lastname,Id   FROM sql_re_up WHERE firstname='eiman'";
    $result = mysqli_query($connect,$sql); //check query executed or not
     /* while($row=mysqli_fetch_array($result))
    {
        echo $row['Id'] . '<br>' ;
     echo $row['firstname'] . '<br>' ; 

     echo $row['lastname'] . '<br>' ;
    }
    */


    while($row=mysqli_fetch_array($result))


    {


    echo "<tr>";
    echo "<td>".$row['Id']."</td>";
    echo "<td>".$row['firstname']."</td>";
    echo "<td>".$row['lastname']."</td>";
    echo "<td>".$row['Id']."<a href='retreive.html?id=".$row['Id']."'><strong>Edit</strong></a> | <a href='retreive.html?id=".$row['Id']."'><strong>Delete</strong></a></td>";

    echo "</tr>";


    }
      echo "</table>";
    /*
      <td><a href="addradiosql.html?cid=<?php echo $row['Id']; ?>"><strong>Edit</strong></a> | <a href="addradiosql.html?action=delete&id=<?php echo $row['Id']; ?>"><strong>Delete</strong></a></td>
    <?php
        <tr> 
          <td><?php echo $row['Id']; ?></td>
          <td><?php echo $row['fileno']; ?></td>
          <td><?php echo $row['gender']; ?></td>

     <td><a href="addradiosql.html?cid=<?php echo $row['Id']; ?>"><strong>Edit</strong></a> | <a href="addradiosql.html?action=delete&id=<?php echo $row['Id']; ?>"><strong>Delete</strong></a></td>
        </tr>
    </table>

    ?>

    */



?>