【问题标题】:Error with bootstrap 3: modal and $_GET my ID引导程序 3 出错:模式和 $_GET 我的 ID
【发布时间】:2015-01-04 22:32:47
【问题描述】:

您好,我正在使用 bootstrap 来更新我网站的用户个人资料,但最近我决定修改它的某些形式,我在将用户 ID 发送到 $_GET 以检索所有个人资料信息并填写所有模式时遇到了一些问题带有数据的文本框。

我不知道我错在哪里,但我尝试用我的脚本传递它,但它还没有奏效。

我有那个错误:注意:未定义索引:mId in

这是我的代码:

这是我的模态:

<div id="exampleModal3" class="modal fade"  aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="exampleModalLabel3">Editar requisición de compras </h4>
</div>
<div class="modal-body">

<form method="POST">
<?php
$id =  $_GET['mId'];
$result = mysql_query("SELECT * FROM users WHERE id='$id'");

$row = mysql_fetch_array($result);
{
?>

<div class="form-group">
<label for="recipient-name1" class="control-label">ID:</label>
<input type="text" class="id form-control"  name="mId" id="mId" >
</div>
<div class="form-group">
<label for="recipient-name2" class="control-label">Username:</label>
<input type="text" class="username form-control" name="username" id="recipient-name2"  value="<?php echo $row['username']; ?>">
</div>
<div class="form-group">
<label for="recipient-name3" class="control-label">Firstname:</label>
<input type="text" class="firstname form-control" name="firstname" id="recipient-name3"  value="<?php echo $row['firstname']; ?>">
</div>
<div class="form-group">
<label for="recipient-name4" class="control-label">Lastname:</label>
<input type="text" class="lastname form-control" name="lastname" id="recipient-name4" value="<?php echo $row['lastname']; ?>">
</div>
<div class="form-group">
<label for="recipient-name5" class="control-label">Email:</label>
<input type="text" class="email form-control" name="email" id="recipient-name5" value="<?php echo $row['email']; ?>">
</div>
<div class="form-group">
<label for="recipient-name6" class="control-label">Password:</label>
<input type="text" class="form-control"  name="password" id="recipient-name6" >
</div>
<?php
}
?>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
<button type="submit" name="Modify" class="btn btn-primary">Guardar</button>
</div>
</form>
</div>
</div>
</div>
</div>

这是我列出所有用户的表格,以及调用我的模式的按钮。

<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>ID</th>
<th>Firstname</th>
<th>LastName</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$result = mysql_query("SELECT * FROM users ORDER BY id");
while($row = mysql_fetch_array($result))
{
?>
<td>

<button type="button" class="open-AddBookDialog btn btn-xs btn-warning" data-id="<?php echo $row['id'];?>" data-toggle="modal" href="#exampleModal3" ><span class="glyphicon glyphicon-edit"></span></button>

</td>
<td ><?php echo $row['username'];?></td>
<td ><?php echo $row['firstname'];?></td>
<td ><?php echo $row['lastname'];?></td>
<td ><?php echo $row['email'];?></td>
</tr>
<?php
}
?>
</tr>
</tbody>
</table>

这是我的脚本:

<script>
$(document).on("click", ".open-AddBookDialog", function () {
var myId = $(this).data('id');
$(".modal-body #mId").val(myId);
});
</script>

【问题讨论】:

  • 你所说的“没有用”是什么意思。
  • 您好,我的意思是我无法将我的 ID 传递给 $_GET 来搜索我的用户的数据。
  • 最好编辑您的答案以改进它。另请阅读stackoverflow.com/help/how-to-ask
  • 谢谢,我已经修改了我的问题,希望对您有所帮助!

标签: mysql twitter-bootstrap get modal-dialog


【解决方案1】:

我在http://wpquestions.com/question/showChrono/id/7922网站上找到了答案:

在modal.php中

 <div class="modal-header">

 <a class="close" data-dismiss="modal">&times;</a>

 <h3>Modal header</h3>

 </div>

 <div class="modal-body">

 <?php

 $post_id = $_GET['ID'];

  echo $post_id;

 ?>

 </div>

 <div class="modal-footer">

 <a class="btn" data-dismiss="modal">Close</a>

 </div>

在我的索引 php 中:

我的按钮调用我的模态:

 <a href="modal.php?ID= WHAT ID YOU WANT " data-toggle="modal"Modal</a>

我的脚本:

  <script type="text/javascript">


  $('[data-toggle="modal"]').click(function(e) {

  e.preventDefault();

  var href = $(this).attr('href');

  if (href.indexOf('#') == 0) {

  $(href).modal('open');

  } else {

 $.get(href, function(data) {

 $('<div class="modal">' + data + '</div>').modal();

 });

}

});

</script>

希望对某人有所帮助!!!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多