Jump to content

How to edit data from database in webpage?


Skylight_lady

Recommended Posts

Hi,

 

I have a webpage that the super administrator log's into. Once the super administrator is logged in he/she can view his/her clients. The super admins clients also have their own clients, once the super admins clients login they can view their own clients details who register with them. What i am trying to do is have a link on that clients name (for the super admins clients) that will bring me to a new page where i can edit his/her details that is stored in the mysql database. I have used INPUT buttons for each clients row in a FORM which works......but i know this is not the right way to do it. This is the code i have used to display the clients with the input button:

<?php
$query = "SELECT ID FROM clients WHERE username = '$username'";
$result = mysql_query($query);
if(mysql_num_rows($result))
{
while($row = mysql_fetch_assoc($result)){
$userID = $row['ID'];
$query = "SELECT * FROM users WHERE userID = '$userID'";
$result = mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<table border="0" cellspacing="3" cellpadding="3" width="100%">
<tr>
<th width="30%"><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Username</font></th>
<th><font face="Arial, Helvetica, sans-serif">Email Address</font></th>
<th> </th>
</tr>
<?php
$i=0;
while ($i < $num) {
$userID=mysql_result($result,$i,"userID");
$name=mysql_result($result,$i,"name");
$username=mysql_result($result,$i,"username");
$email=mysql_result($result,$i,"email");

?>
<tr>
<td width="30%"><?php echo $name; ?></td>
<td><?php echo $username; ?></td>
<td><?php echo $email; ?></td>
<td><form action="http://localhost/single-client.php?userID=<?php echo $userID; ?>&name=<?php echo $name; ?>" method="post" style="margin:0px;">
<input type="hidden" name="selectuser" id="selectuser" value="<?php echo $userID; ?>" /><input type="hidden" name="username1" id="username1" value="<?php echo $username; ?>" /><input type="hidden" name="name1" id="name1" value="<?php echo $name; ?>" /><input type="submit" name="submit" value="View Info" class="button" /></form></td>
</tr>
<?php
$i++;
}}}
?>
</table>

 

From the above code when i use the following code:

?userID=<?php echo $userID; ?>&name=<?php echo $name; ?>

It doesn't make a difference .... it just displays the correct userID and name in the link.

 

Once the INPUT button is clicked it will bring you to this page:

<?php
$query = "SELECT * FROM users WHERE userID = '".$_POST['selectuser']."' AND username = '".$_POST['username1']."'";
$result = mysql_query($query);
if(mysql_num_rows($result))
{
$userID = $_POST['selectuser'];
while($row = mysql_fetch_assoc($result)){
$name = $row['name'];
$userID = $row['userID'];
$email = $row['email'];
$username = $row['username'];
$registered = $row['registered'];
$last = $row['last'];
?>
<?php echo $brokerID; ?>
<table border="0" cellspacing="3" cellpadding="3" width="100%" summary="Client table">
<tr>
<td><form action="http://localhost/single-client.php?userID=<?php echo $userID; ?>&name=<?php echo $name; ?>" method="post" style="margin:0px;">
<input type="hidden" name="selectuser" id="selectuser" value="<?php echo $userID; ?>" /><input type="hidden" name="username1" id="username1" value="<?php echo $username; ?>" /><input type="hidden" name="name1" id="name1" value="<?php echo $name; ?>" /><input type="submit" name="submit" value="Income" class="button" /></form></td>
<td><form action="http://localhost/single-client.php?userID=<?php echo $userID; ?>&name=<?php echo $name; ?>" method="post" style="margin:0px;">
<input type="hidden" name="selectuser" id="selectuser" value="<?php echo $userID; ?>" /><input type="hidden" name="username1" id="username1" value="<?php echo $username; ?>" /><input type="hidden" name="name1" id="name1" value="<?php echo $name; ?>" /><input type="submit" name="submit" value="Bills" class="button" /></form></td>
</tr>
</table>
<h2>Client Profile - <?php echo $_POST['name1']; ?></h2>
<table border="0" cellspacing="3" cellpadding="3" width="100%">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Username</font></th>
<th><font face="Arial, Helvetica, sans-serif">Email Address</font></th>
<th><font face="Arial, Helvetica, sans-serif">Registered</font></th>
<th><font face="Arial, Helvetica, sans-serif">Last</font></th>
</tr>
<tr>
<td><?php echo $name; ?></td>
<td><?php echo $username; ?></td>
<td><?php echo $email; ?></td>
<td><?php echo $registered; ?></td>
<td><?php echo $last; ?></td>
</tr>
</table>
<?php
}
}
else
{
   echo "<p>Error</p>";
}
?>

 

This page displays the correct user info. Is there a way to do it differently instead of using FORMS and INPUT buttons? and rather using links? Any help would be greatly appreciated.

 

Link to comment
Share on other sites

you can send the variables in the URL and have a link/image for the user to click. Then retrieve with $_GET

i.e. page1

$sql = @mysql_query("SELECT userID, name FROM users WHERE company='4'");
while ($row = mysql_fetch_array($query)) {
echo "<p><b>{$row['name']}</b><br/>
echo "<a href='editPage.php?user={$row['user']}'>Edit User</a>";
echo '</p>';
}

 

then on editPage.php

$userID = mysql_real_escape_string($_GET['user']);
$sql = @mysql_query("SELECT
//do whatever

 

you'll have to ensure the logged in user is allowed to edit/modify the selected user on the editPage.php, by using session variables etc

Link to comment
Share on other sites

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.