【发布时间】: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">×</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