如何通过模态编辑mysql中的数据

我一直在使用此代码时遇到错误。 我是新手,并使用模态进行操作。 我曾经为所有’花式’forms运行儿童表格,但现在我正朝着模态迈进。 这是我获取模态的代码:

 

<?php $result = mysql_query("SELECT * FROM `players` ORDER BY `players`.`user` ASC") or die(mysql_error()); echo "
"; echo ""; while($row = mysql_fetch_array( $result )) { echo ""; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ""; } echo "
Username Rank Position DoP Tag AiT Service Stripes Notes
' . $row['user'] . '' . $row['rank'] . '' . $row['position'] . '' . $row['date'] . '' . $row['tag'] . '' . $row['ait'] . '' . $row['ss'] . '' . $row['notes'] . 'DeleteDD
HD
"; ?>

这是我的edit.php:

    <?php if ($error != '') { echo '
'.$error.'
'; } ?>
<input type="hidden" name="id" value=""/>
Username: *
<input class="tb5" type="text" name="user" value="" />

Rank: * Current is
<option value="recruit" >Pending Rank <option value="officer" >PVT <option value="leader" >PV2

Position:
<input class="tb5" type="text" name="position" value="" />

Date: *
<input class="tb5" type="text" name="date" value="" />

Tag: *
<input class="tb5" type="text" name="tag" value="" />

AiT's:
<input class="tb5" type="text" name="ait" value="" />

Service Stripes:
<input class="tb5" type="text" name="ss" value="" />

Notes:
<input class="tb5" type="text" name="notes" value="" />

<input type="hidden" name="id" value=""/>
Username: *
<input class="tb5" type="test" name="user" value="" disabled />

Rank: * Current is
<option value="recruit" >PVT <option value="officer" >PV2

Position:
<input class="tb5" type="hidden" name="position" value="" />

Date: *
<input class="tb5" type="text" name="date" value="" />

Tag: *
<input class="tb5" type="text" name="tag" value="" />

AiT's:
<input class="tb5" type="text" name="ait" value="" />

Service Stripes:
<input class="tb5" type="hidden" name="ss" value="" />

Notes:
<input class="tb5" type="hidden" name="notes" value="" />

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现在可能已经解决了这个问题,或者采取了不同的方法,我已经发布了答案,以便它可能对其他人有用。

试试这个..
//编辑链接或按钮。

    //ajax_edit.php //modal window  

//脚本