如何通过模态编辑mysql中的数据
我一直在使用此代码时遇到错误。 我是新手,并使用模态进行操作。 我曾经为所有’花式’forms运行儿童表格,但现在我正朝着模态迈进。 这是我获取模态的代码:
<?php $result = mysql_query("SELECT * FROM `players` ORDER BY `players`.`user` ASC") or die(mysql_error()); echo " "; echo "Username Rank Position DoP Tag AiT Service Stripes Notes "; while($row = mysql_fetch_array( $result )) { echo ""; echo '' . $row['user'] . ' '; echo '' . $row['rank'] . ' '; echo '' . $row['position'] . ' '; echo '' . $row['date'] . ' '; echo '' . $row['tag'] . ' '; echo '' . $row['ait'] . ' '; echo '' . $row['ss'] . ' '; echo '' . $row['notes'] . ' '; echo ' '; echo 'Delete '; echo 'DD
HD '; echo " "; } echo "
"; ?>
这是我的edit.php:
<?php if ($error != '') { echo ''.$error.''; } ?> 0) { $id = $_GET['id']; $result = mysql_query("SELECT * FROM players WHERE id=$id") or die(mysql_error()); $row = mysql_fetch_array($result); if($row) { $id = $row['id']; $user = $row['user']; $rank = $row['rank']; $position = $row['position']; $date = $row['date']; $tag = $row['tag']; $ait = $row['ait']; $ss = $row['ss']; $notes = $row['notes']; @renderForm($id, $user, $rank, $position, $date, $tag, $ait, $ss, $notes, ''); } else { echo "No results!"; } } else { echo 'Error!'; } } ?>
问题是我一直得到’错误!’ 模态框中的消息,而不是其他任何内容。 我正在尝试做的目标是从存储在我的数据库中的ID中提取数据。 我认为问题实际上是当我点击用户编辑时它没有抓取ID。 坦率地说,我不知道如何通过模态编辑ID。 非常感谢帮助。 谢谢
额外奖励:我无法在同一页面上打开两个模态。 如果我在同一页面上有两个,则没有一个出现:
您的编辑按钮不会将ID传递给edit.php
,这就是模式未激活的原因。 您需要在打开之前填充编辑模式的内容,而不是在加载时填充。 使用include
将加载编辑页面而不向其传递ID。
重写编辑按钮以包含ID
JS用于在打开模态时加载编辑表单
//jQuery function for loading data $("#editModal").on('show.bs.modal', function(event){ var button = $(event.relatedTarget); //bootstrap way of retrieving data-* attributes //data-formid in this case var id = button.data('formid'); $.get(yourSiteUrl+'/classes/forms/edit.php?id='+id, function(data) { $("#editModal .modal-title").html(data); //Resize the modal to the size of the loaded form. $("#editModal").modal("handleUpdate"); }); });
查看本教程以了解bootstrap模式
PS:我知道OP现在可能已经解决了这个问题,或者采取了不同的方法,我已经发布了答案,以便它可能对其他人有用。