简体   繁体   English

来自MySQL数据库的数据-编辑条目

[英]Data from MySQL Database - Edit entry

I hope that someone can help me with a little issue. 我希望有人可以帮我一点问题。 I have no idea how to solve that. 我不知道该如何解决。 For someone who works with MySQL and PHP it should be easy to explain I guess. 我猜对于使用MySQL和PHP的人来说,应该很容易解释。 Anyway here is what I need: 无论如何,这就是我需要的:

I created an admin interface with PHP. 我用PHP创建了一个管理界面。 Inside the admin interface I have a table with entries from my database. 在管理界面中,我有一个表,其中包含数据库中的条目。 So inside the table I can see the ID, username, first name, last name and so on from every single user. 因此,在表格内,我可以看到每个用户的ID,用户名,名字,姓氏等。

在此处输入图片说明

Now on the right side you can see the text "Bearbeiten" which means "Edit" in English. 现在,在右侧,您会看到文本“ Bearbeiten”,其英文含义为“ Edit”。 If I click on edit I am redirected to my edit page. 如果单击“编辑”,我将被重定向到我的编辑页面。 Problem ist, that the edit.php ist the same for every user. 问题在于,edit.php对每个用户而言都是相同的。 What I want now is, that if I click on "Bearbeiten" that I will be forwarded to the edit.php BUT that I am able to edit the specific user there. 我现在想要的是,如果单击“ Bearbeiten”,我将被转发到edit.php,但我可以在那里编辑特定用户。

For example if I click on " Bearbeiten " in the row where the user is with User ID 1 than I want to be redirected to edit.php?id=1 so that I am able to edit only the selected profile. 例如,如果我单击用户ID为1的用户所在行中的“ Bearbeiten ”,则我要重定向至edit.php?id=1这样我就只能编辑所选的配置文件。

Can someone help me? 有人能帮我吗? What do I need to do inside my code? 我需要在代码中做什么? I would really appreciate your help! 我将衷心感谢您的帮助!

EDIT: 编辑:

Here is my table code at the user overview site: 这是我在用户概述站点上的表代码:

<table class="table table-striped responsive-utilities jambo_table bulk_action">
                                        <thead>
                                            <tr class="headings">

                                                <th class="column-title">ID </th>
                                                <th class="column-title">Schule</th>
                                                <th class="column-title">Vorname </th>
                                                <th class="column-title">Nachname </th>
                                                <th class="column-title">Registriert am </th>
                                                <th class="column-title">Aktiv </th>
                                                <th class="column-title no-link last"><span class="nobr">Profil</span>
                                                </th>
                                                <th class="bulk-actions" colspan="7">
                                                    <a class="antoo" style="color:#fff; font-weight:500;">Mehrfachauswahl ( <span class="action-cnt"> </span> ) <i class="fa fa-chevron-down"></i></a>
                                            </th>
                                </tr>
                            </thead>
                            <?php while ($row = $erg->fetch_assoc()) { ?> 
                            <tbody>
                                <tr class="even pointer">
                                    <td class=" "><?php echo $row['id']; ?></td>
                                    <td class=" "><?php echo $row['schule']; ?></td>
                                    <td class=" "><?php echo $row['firstname'];?></td>
                                    <td class=" "><?php echo $row['lastname']; ?></td>
                                    <td class=" "><?php echo $row['registration']; ?></td>
                                    <td class="a-right a-right "><?php echo $row['active']; ?></td>
                                    <td class=" last"><a href="edit_profil_teacher.php?id=<?php echo $id; ?>">Bearbeiten</a>
                                                    </td>
                                            </tr>           
                            <?php } ?>

                             </tbody>
                            <?php $erg->close(); ?> 
                                    </table>

Here is what I entered at the top of my edit page: 这是我在编辑页面顶部输入的内容:

<?php
$user_id = (int)$_GET['id'];
?>

Problem right now is that URL at user overview page changed to edit.php?id= but that´s it. 现在的问题是,用户概述页面上的URL更改为edit.php?id =,仅此而已。 It does not select the correct ID. 它没有选择正确的ID。 What am I missing? 我想念什么?

Thanks, Chris 谢谢克里斯

Assuming in the listing page you are looping around a mysql result to generate the HTML, you need to add the id to the anchor tags href tag. 假设在列表页面中,您正在遍历mysql结果以生成HTML,则需要将id添加到锚标记href标记中。

Code has been changed to use the $row['id'] from provided coded. 代码已更改为使用提供的编码中的$ row ['id']。

On the link for "Bearbeiten" change the: 在“ Bearbeiten”的链接上,更改:

<a href="edit.php">Bearbeiten</a>

to: 至:

<a href="edit.php?id=<?php echo $row['id']; ?>">Bearbeiten</a>

Change $id to whatever you're calling the PHP variable for the ID column, on your edit.php page you can then pull user details from the database for that user ID. 将$ id更改为您为ID列调用的PHP变量,然后在edit.php页面上,您可以从数据库中提取该用户ID的用户详细信息。

<a href="edit.php?id=<?php echo $id; ?>">Bearbeiten</a>

And then in the edit.php page at the top: 然后在顶部的edit.php页面中:

$user_id = (int)$_GET['id'];

Hope that helps. 希望能有所帮助。

Like members have already suggested, put this in a loop something like: 就像成员已经建议的那样,将其放入一个循环中,如下所示:

<?php
 while($row=$stmt->fetch(PDO::FETCH_ASSOC))
 { 
    $id = $row['ID'];
    $name = $row['Name Eleternteil'];

?>
<td><?php echo $id; ?></td>
<td><?php echo $name; ?></td>
<td><a href="edit.php?id=<?php echo $id; ?>">Bearbeiten</a></td>
<?php } ?>

This shoulkd take you to the next page with the unique ID and then on the edit.php get the id and do whatever you want by simply using: 这将带您进入具有唯一ID的下一页,然后在edit.php获取ID并只需使用以下命令即可完成您想做的一切:

<?php
    $edit = $_GET['id'];
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM