【问题标题】:Unable To Update_View_Delete Modal Dialog BootstrapUnable To Update_View_Delete 模态对话框引导程序
【发布时间】:2017-05-11 03:02:28
【问题描述】:

我需要帮助...我正在尝试使用 PHP 和模式对话框引导程序制作插入/更新/查看/删除表单。 我设法做插入过程。但无法从引导模式对话框更新、查看和删除。

数据库连接&进程

<?php
define('host', 'localhost');
define('user', 'root');
define('password', '');
define('db_name', 'testing');
$connect = NEW mysqli(host,user,password,db_name) or die (mysqli_error());
if(isset($_POST['add']))
{
$name = $connect->real_escape_string($_POST['name']);
$email = $connect->real_escape_string($_POST['email']);
$address = $connect->real_escape_string($_POST['address']);
if($SQL)
{
?>
<script>
alert('Data Inserted!.');
        window.location.href='crud.php';
   </script>
<?php
    }
}
if(isset($_GET['edit']))
{
$SQL = $connect->query("SELECT * FROM tbl_employee WHERE id=".$_GET['edit']);
$view= $SQL->fetch_array(MYSQLI_BOTH);
}
if(isset($_POST['update']))
{
$SQL = $connect->query("UPDATE tbl_employee SET Nama='".$_POST['name']."', Email='".$_POST['email']."', Address='".$_POST['address']."' WHERE id=".$_GET['edit']);
if($SQL)
{
?>
<script>
alert('Data Updated.');
        window.location.href='crud.php';
   </script>
       <?php
    }
}
if(isset($_GET['delete']))
{
    $SQL = $connect->query("DELETE FROM tbl_employee WHERE id=".$_GET['delete']);
if($SQL)
{
?>
<script>
alert('Data Deleted!.');
        window.location.href='crud.php';
   </script>
<?php
    }
}
?>

表格

<div id="employee_table">
        <table class="table table-bordered">
        <tr>
            <th width=10%>#</th>
            <th width=60%>Employee Name</th>
            <th width=20%>Action</th>
        </tr>
        <?php
        while($row = mysqli_fetch_array($result))
        {
            @$no++;
         ?>    
        <tr>
            <td><?php echo $no; ?></td>
            <td><?php echo $row["name"]; ?></td>
            <td><?php echo $row["email"]; ?></td>
            <td><?php echo $row["address"]; ?></td>
            <td>
            <input type="button" name="view" value="View" id="<?php echo $row["id"]; ?>" class="btn btn-info btn-xs view_data" 
            data-toggle="modal" data-target="#view" />
            <input type="button" name="view" value="Update" id="<?php echo $row["id"]; ?>" class="btn btn-info btn-xs 
            update_data" 
            data-toggle="modal" data-target="#update" />
            <input type="button" name="view" value="Delete" id="<?php echo $row["id"]; ?>" class="btn btn-info btn-xs 
            delete_data" 
            data-toggle="modal" data-target="#delete" />
            </td>
        </tr>
        <?php
        }
        ?>
        </table>
        </div> 

查看模式对话框

<div id="view" class="modal fade">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4>Employee Details</h4>
        </div>
        <div class="modal-body" id="employee_detail">
        <form method="post" id="insert_form" action="">
<label>Employee name</label>
<input type="text" name="name" id="name" class="form-control" value="<?php if(isset($_GET['update'])){ echo $view['1']; } ?>" readonly="" />
<br>
<label>Employee Address</label>
<textarea name="address" id="address" class="form-control" value="<?php if(isset($_GET['update'])){ echo $view['2']; } ?>"readonly=""></textarea>

        </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </div>
</div>

employee info unable to view

【问题讨论】:

    标签: php html twitter-bootstrap bootstrap-modal


    【解决方案1】:

    您不能这样查看员工详细信息。

    使用 ajax 调用显示详细信息。

    你在哪里传递你在视图按钮中分配的 id???

    如果您是 PHP 初学者,请查看以下链接。

    它将帮助您进行 CRUD 操作。

    教程链接:http://www.itechempires.com/2016/03/php-mysql-crud-create-read-update-delete-operations-using-jquery/

    演示链接:http://demos.itechempires.com/php-mysql-crud-operations/

    或者使用这个:

    <input type="button" name="view" value="View" onclick="view_data('<?=$row['name']?>','<?=$row['address']?>')" class="btn btn-info btn-xs view_data"
                         data-toggle="modal" data-target="#view" />
    
    <script type="text/javascript">
         function view_data(name,address) {
              $('#view input[name=name]').val(name);
              $('#view input[name=address]').val(address);
         }
    
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 2019-08-08
      • 1970-01-01
      相关资源
      最近更新 更多