0

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. Anyway here is what I need:

I created an admin interface with 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.

enter image description here

Now on the right side you can see the text "Bearbeiten" which means "Edit" in English. If I click on edit I am redirected to my edit page. Problem ist, that the edit.php ist the same for every user. 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.

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.

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. It does not select the correct ID. What am I missing?

Thanks, Chris

7
  • Well my problem is I am not sure where to start? I believe it is possibe with PHP and maybe a $_GET function but I do not know where or how I should start Commented Aug 21, 2015 at 16:14
  • It is most definitely possible. You should research basic CRUD operations in PHP with mysqli or pdo and you should be able to figure it out from there. To answer you other question, yes you can pass in the ID of the item you are trying to edit with a GET parameter. A word of caution though, it'd be very easy to simply change which ID you are editing by changing the URL, so be sure to implement proper security. Commented Aug 21, 2015 at 16:17
  • 5
    "What do I need to do inside my code?" - Two operative words here being the first and the last in that sentence..., including the question mark - That's just it... "What code"? Commented Aug 21, 2015 at 16:18
  • updated my question with my code! Hope that helps to help :) Commented Aug 21, 2015 at 16:30
  • @ChristophC. it should work now, no? Commented Aug 21, 2015 at 16:32

3 Answers 3

1

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.

Code has been changed to use the $row['id'] from provided coded.

On the link for "Bearbeiten" change the:

<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.

Sign up to request clarification or add additional context in comments.

4 Comments

I was about to ask him why and @RiggsFolly fixed it.
Thanks for that fast help. There is just one thing I do not understand: "Change $id to whatever you're calling the PHP variable for the ID column, on your edit.php page"! What do you exactly mean by that? What do I have to change on the edit.php so that I knows which user it is?
Just changed it again, didnt see the missing ?id=<?php echo $id; ?> first time. edit.php just needs to get the id from $_GET['id']
Hey Christoph C. -- I just meant to use the variable name you used to display the ID in the ID column.
0

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:

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

Comments

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

And then in the edit.php page at the top:

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

Hope that helps.

2 Comments

Thanks for your help! I added your link code to my user.php where my table is and I added $user_id = (int)$_GET['id']; to my edit.page! Now when I scroll over the "Bearbeiten" link it changes to edit.php?id= but there is no ID. What am I missing?
You just need to make sure that $id is the variable name on the main user page for the users ID.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.