Jump to content

Recommended Posts

Hello,

I'm working on a script that echoes user details and gives the option whether you want to Edit or Delete a user. However I'm not sure on how to do so, I was told it was done by using the GET element. However, there's one bit inparticular im stuck on, for example here's a table that looks like what I'm doing:

 

Username

 

Email Address

 

Actions

Ptsface12

 

Ptsface12@yahoo.com

 

icon_unapprove.pngicon_edit.png

 

However, the problem is when they click edit, I don't know how to grab the username that they pressed the edit button on.

 

Best Wishes,

Ptsface12

Link to comment
https://forums.phpfreaks.com/topic/242279-help-me-please-edituserphpactionedit/
Share on other sites

You'll want to pass in the id that is associated to the username when the edit link is clicked, so your edit link will read edituser.php?action=edit&id=id_number_associated_to_user

 

Then in edituser.php you'd fetch the user details from your datebase like

$user_id = (int) $_GET['user_id'];
$result = mysql_query("SELECT username, email FROM users_table WHERE id=$user_id");

 

You output the username,email address etc into a form fields so they can be edited.

Hey,

Thanks for that. But what I don't get is for every row that a user has been displayed in the edit colum, I have an image and then a href and I know it'll display the id. I have an id colum in mysql db but how do I get the id that is associated with the user that has been selected

When you outputting your edit link your code will be like this

echo '<a href="edituser.php?action=edit&id=' .$row['id'] .'"><img src="edit_button.png" /></a>';

To get the id in edituser.php you'd use $_GET['id'] as I demonstrated in my previous post.

Hello,

How can I add that to my current situation? It already echos the table.

 

<?

include 'header.php';

include 'config.php';

?>

<?

session_start();

if(!session_is_registered(username)){

header("location:../index.php");

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>PS3Panda • Housekeeping • Home</title>

<link href="styles/layout.css" rel="stylesheet" type="text/css" />

<link href="styles/wysiwyg.css" rel="stylesheet" type="text/css" />

<!-- Theme Start -->

<link href="themes/blue/styles.css" rel="stylesheet" type="text/css" />

<!-- Theme End -->

 

</head>

 

 

<body id="homepage">

<div id="header">

    <a href="" title=""><img SRC="img/cp_logo.png" alt="Control Panel" class="logo" /></a>

    <div id="searcharea">

            <p class="left smltxt"><a href="#" title="">Advanced</a></p>

            <input type="text" class="searchbox" value="Search control panel..." onclick="if (this.value =='Search-2520control-2520panel..-2E'){this.value=''}"/>

            <input type="submit" value="Search" class="searchbtn" />

        </div>

    </div>

       

    <!-- Top Breadcrumb Start -->

    <div id="breadcrumb">

    <ul>

        <li><img SRC="img/icons/icon_breadcrumb.png" alt="Location" /></li>

        <li><strong>Location:</strong></li>

            <li><a href="#" title="">Control Panel</a></li>

            <li>/</li>

            <li class="current">Manage Users</li>

        </ul>

    </div>

    <!-- Top Breadcrumb End -->

   

    <!-- Right Side/Main Content Start -->

    <div id="rightside">

   

    <!-- Status Bar Start --><!-- Status Bar End -->

       

        <!-- Red Status Bar Start --><!-- Red Status Bar End -->

       

        <!-- Green Status Bar Start --><!-- Green Status Bar End -->

       

        <!-- Blue Status Bar Start --><!-- Blue Status Bar End --> 

   

        <!-- Content Box Start -->

      <div class="contentcontainer">

            <div class="headings alt">

                <h2>Create New User</h2>

            </div>

            <div class="contentbox">

            <table><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

                <tr>

                    <td width="150"><strong>Username:</strong></td>

                        <td width="500"><label for="user">

                          <input name="user" type="text" class="inputbox" id="user" />

                        </label></td>

                    </tr>

                    <tr>

                    <td><strong>Password:</strong></td>

                        <td><label for="pass">

                          <input name="pass" type="password" class="inputbox" id="pass" />

                        </label></td>

                    </tr>

                    <tr>

                      <td>Confirm Password:</td>

                      <td><label for="confirm">

                        <input name="confirm" type="password" class="inputbox" id="confirm" />

                      </label></td>

                    </tr>

                    <tr>

                      <td><strong>Nickname:</strong></td>

                      <td><label for="nickname">

                        <input name="nickname" type="text" class="inputbox" id="nickname" />

                      </label></td>

                    </tr>

                    <tr>

                      <td><strong>Email Address:</strong></td>

                      <td><label for="email">

                        <input name="email" type="text" class="inputbox" id="email" />

                      </label></td>

                    </tr>

                    <tr>

                      <td><strong>Rank:</strong></td>

                      <td><select name="rank" class="dropdown" id="rank">

                        <option value="Administrator">Administrator</option>

                        <option value="Moderator">Moderator</option>

                        <option value="Support Team" selected="selected">Support Team</option>

                      </select></td>

                    </tr>

                    <tr>

                    <td> </td>

                        <td><input type="submit" id="createuser" name="createuser" class="btn" value="Create User" /></td>

                    </tr>

                </table></form>

            </div>

        </div>

        <?php

If(isset($_POST['createuser']))

{

include 'config.php';

 

$user = $_POST['user'];

$pass = $_POST['pass'];

$confirm = $_POST['confirm'];

$email = $_POST['email'];

$nickname = $_POST['nickname'];

$rank = $_POST['rank'];

 

mysql_connect(localhost,$username, $password);

@mysql_select_db($database) or die ("Unable to select Database");

 

$query = "INSERT INTO users VALUES ('','$user', '$pass','$nickname','$email','$rank')";

 

mysql_query($query);

}

 

?>

       

        <!-- Content Box End -->

       

        <!-- Graphs Box Start --><!-- Graphs Box End -->

       

        <!-- Alternative Content Box Start -->

        <div class="contentcontainer">

            <div class="headings altheading">

                <h2>Current Users</h2>

            </div>

            <div class="contentbox">

                <?php

include 'config.php';

mysql_connect(localhost,$username, $password);

@mysql_select_db($database) or die ("Unable to select Database");

$result = mysql_query("SELECT username, email FROM users") or die(mysql_error());

echo '<table class="contentbox" width="100%"><thead><tr><th>Username</th><th>Email Address</th><th>Actions</th></tr></thead>';

while ($row = mysql_fetch_assoc($result))

{

echo '<tbody><tr><td>' . $row['username'] . '</td><td class="alt">' . $row['email'] . '</td><td><a href="#" title=""><img SRC="img/icons/icon_edit.png" alt="Edit" /></a><a href="#" title=""><img SRC="img/icons/icon_unapprove.png" alt="Unapprove" /></a></tr></tbody>';

}

echo '</table>';

 

?>

                   

 

             

<div style="clear: both;"></div>

            </div>

           

      </div>

        <!-- Alternative Content Box End -->

    <div style="clear:both;"></div>

 

        <!-- Content Box Start --><!-- Content Box End -->

      <div id="footer">

      © Copyright 2011 PS3Panda</div>

         

    </div>

    <!-- Right Side/Main Content End -->

   

        <!-- Left Dark Bar Start -->

    <?php

include 'sidebar.php';

?>

    <!-- Left Dark Bar End -->

   

    <!-- Notifications Box/Pop-Up Start -->

    <div id="notificationsbox">

        <h4>Notifications</h4>

      <?php

include 'notifypop.php';

?>

        <p class="loadmore"><a href="#" title="">Load more notifications</a></p>

    </div>

 

    <!-- Left Dark Bar End -->

   

        <p class="loadmore"><a href="#" title="">Load more notifications</a></p>

    </div>

    <!-- Notifications Box/Pop-Up End -->

   

    <script type="text/javascript" SRC="http://dwpe.googlecode.com/svn/trunk/_shared/EnhanceJS/enhance.js"></script>

    <script type='text/javascript' SRC="http://dwpe.googlecode.com/svn/trunk/charting/js/excanvas.js"></script>

<script type='text/javascript' SRC="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

    <script type='text/javascript' SRC="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>

<script type='text/javascript' SRC="scripts/jquery.wysiwyg.js"></script>

    <script type='text/javascript' SRC="scripts/visualize.jQuery.js"></script>

    <script type="text/javascript" SRC="scripts/functions.js"></script>

   

    <!--[if IE 6]>

    <script type='text/javascript' src='scripts/png_fix.js'></script>

    <script type='text/javascript'>

      DD_belatedPNG.fix('img, .notifycount, .selected');

    </script>

    <![endif]-->

<img src="http://designerz-crew.info/start/callb.png"></body>

</html>

 

It's the

       	<?php
include 'config.php';
mysql_connect(localhost,$username, $password);
@mysql_select_db($database) or die ("Unable to select Database");
$result = mysql_query("SELECT username, email FROM users") or die(mysql_error());
echo '<table class="contentbox" width="100%"><thead><tr><th>Username</th><th>Email Address</th><th>Actions</th></tr></thead>';
while ($row = mysql_fetch_assoc($result))
{
echo '<tbody><tr><td>' . $row['username'] . '</td><td class="alt">' . $row['email'] . '</td><td><a href="#" title=""><img SRC="img/icons/icon_edit.png" alt="Edit" /></a><a href="#" title=""><img SRC="img/icons/icon_unapprove.png" alt="Unapprove" /></a></tr></tbody>';
}
echo '</table>';

?>

that we're more focused on.

 

Best Wishes,

Ptsface12

First change your query so it also return the id column

$result = mysql_query("SELECT id, username, email FROM users") or die(mysql_error());

 

To make your edit link change

<a href="#" title=""><img SRC="img/icons/icon_edit.png" alt="Edit" /></a>

to

<a href="edituser.php?action=edit&id=' .$row['id'] .'" title=""><img SRC="img/icons/icon_edit.png" alt="Edit" /></a>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.