Jump to content

Decrypt password and add delete button


bpburrow

Recommended Posts

So I've got this really great table that neatly displays client data.  Problem is the password is displayed as stored using the md5 function.  How do I go about decrypting the password? 

 

Second, I'd like to add a delete capability (button, check box or radio button) at the end of each row.  Problem is this is outside the scope of my php know how.  Is there a simple solution I can incorporate into my existing script or will it require a lot of restructuring?

 

Here's how my table looks (I added Delete as part of this post):

 

Client count = 4

client_id firstName lastName  username passwd                                 email

10         jane         doe           test1       5a105e8b9d40e1329780     test1@hotmail.com    Delete // Would like to add delete button

11         jane         doe           test2       ad0234829205b9033196     test2@hotmail.com    Delete

12         john         doe           test3       8ad8757baa8564dc136c     test3@hotmail.com    ......etc

13         john         doe           test4       86985e105f79b95d6bc9      test4@hotmail.com

 

 

client_list.php

<?php
						// SQL query
						$query="SELECT * FROM Client";
						$result=mysql_query($query) or die('Query failed: ' . mysql_error());

						$num_rows = mysql_num_rows($result);

						// Error message for empty DB
						if ($num_rows == 0){
							$errors[] = "Database contains no client records.";
						} else {
							// Print results in HTML
							// Number of records
							$num_rows = mysql_num_rows($result);
							echo "<p class=\"indent\">Client count = $num_rows</p>\n";

							// Set up table
							echo "<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" align=\"center\">\n";

							$line = mysql_fetch_array($result, MYSQL_ASSOC);
								echo "\t<tr>\n";
								// echo "\t\t<th>#</th>\n";
								// Set title row for data
								foreach (array_keys($line) as $col_value){
									echo "\t\t<th class=\"listTitle\">$col_value</th>\n";
								}
								echo "\t</tr>\n";

							//$i=0;
							do{
								echo "\t<tr>\n";
								//$i++;
								//echo "\t\t<th>$i</th>\n";
								foreach ($line as $col_value){
									echo "\t\t<td>$col_value</td>\n";
								}
									echo "\t</tr>\n";
							}
							while ($line = mysql_fetch_array($result, MYSQL_ASSOC));
							echo "</table><br />";
						}

						if(count($errors) > 0){
							echo "<div class='error'>";
							foreach($errors AS $error){
								echo $error . "<br />";
							}
							echo "</div>";
							echo "<a href=\"../admin/client_new.php\">Add Client</a>";
							//we use javascript to go back rather than reloading the page 
							// so the user doesn't have to type in all that info again.
						}

						mysql_close();
					?> 

Link to comment
Share on other sites

security issues aside you could uses a  link such as below ( you can substitute a image for the word delete using <img> ) which would

redirect to a page you write deleting the user then redirect back to the page you started from listing all your users

 

<a href="deleteuser.php?email=<?php echo $email;?>)">Delete</a>

Link to comment
Share on other sites

I'll have to think about the password issue and come back to it later.

 

As for the delete option, I've tried setting up a hyperlink for a delete.php.  I'm running into formatting issues where the delete links line up in one row instead of at the end of each row.

Link to comment
Share on other sites

The link appears after each field.  How do I adjust so it only shows at the end of the rows?

 

I added the following:

<?php
foreach ($line as $col_value){
  echo "\t\t<td>$col_value<a href=\"delete.php\">Delete</a></td>\n";
}
?>

 

And this is what I've got:

 

Client count = 4

client_id    firstName      lastName    username        passwd                                          email

10Delete  janeDelete    doeDelete    test1Delete    5a105e8b9d40e1329780Delete    test1@hotmail.comDelete 

Link to comment
Share on other sites

I scrapped my previous table and decided to start over.  How that the html formatting is out of the way I'm stuck on the delete action.  Rows aren't being deleted after pressing button. 

 


<?php
							// SQL query
							$query="SELECT * FROM Client";
							$result=mysql_query($query) or die('Query failed: ' . mysql_error());

							$num_rows = mysql_num_rows($result);

							// Error message for empty DB
							if ($num_rows == 0){
								$errors[] = "Database contains no client records.<br />
											<div class=\"bodyText\"><a href=\"../admin/client_new.php\">Add Client</a></div>";
							} else {
								// Print results in HTML
								// Number of records
								$num_rows = mysql_num_rows($result);
								echo "<p class=\"indent\">Client count = $num_rows</p>\n";

								echo "<table border=\"0\" cellpadding=\"4\" cellspacing=\"4\" align=\"center\">
									<tr>
									<th align=center>Delete</th>
									<th>ID</th>
									<th>Firstname</th>
									<th>Lastname</th>
									<th>Username</th>
									<th>Email</th>
									</tr>\n";

								while($row=mysql_fetch_array($result))
								{
									echo "<tr>\n";
									echo "\n<td align=center><input type=checkbox name=". $row['client_id'] . " id=". $row['client_id'] . " value=". $row['client_id'] . " /></td>";
									echo "\n<td>". $row['client_id'] . "</td>";
									echo "\n<td>". $row['firstName'] . "</td>";
									echo "\n<td>". $row['lastName'] . "</td>";
									echo "\n<td>". $row['username'] . "</td>";
									echo "\n<td>". $row['email'] . "</td>";
									echo "\n</tr>";
								}
									echo "\n<td><input class=\"delete\" type=\"submit\" name=\"delbtn\" value=\"Delete\" /></td>";
									echo "\n</table>\n";
							}	
							$id= $_POST["client_id"];
							if(isset($_POST['delbtn'])) {
							// Loop through check boxes
							foreach($_POST as $id) {
								//  Delete  record from database
								mysql_query("DELETE FROM Client WHERE id='$id'"); 
								}
							}

							if(count($errors) > 0){
								echo "<div class='error'>";
								foreach($errors AS $error){
									echo $error . "<br />";
								}
								echo "</div>";
								echo "<div class=\"bodyText\"><a href=\"../admin/client_new.php\">Add Client</a></div>";
								//we use javascript to go back rather than reloading the page 
								// so the user doesn't have to type in all that info again.
							}
							//close DB
							mysql_close();
						?> 

Link to comment
Share on other sites

I cannot see any form tags..

Also to avoid errors I would do this in HTML

<input type=\"checkbox\" name=\"deletes[]\" id=\"". $row['client_id'] . "\" value=\"". $row['client_id'] . "\" />

then iterate through that with

foreach ($_POST['deletes'] as $value)

 

Just my 2 cents

Link to comment
Share on other sites

I didn't show entire script on last post.  Here's what I have with recommended changes.  Still having the same problem.

 

<form action="client_list.php" method="post" class="clearfix">
					<fieldset class="clearfix">
						<legend> Client List </legend>
						<?php
							// SQL query
							$query="SELECT * FROM Client";
							$result=mysql_query($query) or die('Query failed: ' . mysql_error());

							$num_rows = mysql_num_rows($result);

							// Error message for empty DB
							if ($num_rows == 0){
								$errors[] = "Database contains no client records.<br />
											<div class=\"bodyText\"><a href=\"../admin/client_new.php\">Add Client</a></div>";
							} else {
								// Print results in HTML
								// Number of records
								$num_rows = mysql_num_rows($result);
								echo "<p class=\"indent\">Client count = $num_rows</p>\n";

								echo "<table border=\"0\" cellpadding=\"4\" cellspacing=\"4\" align=\"center\">
									<tr>
									<th align=center>Delete</th>
									<th>ID</th>
									<th>Firstname</th>
									<th>Lastname</th>
									<th>Username</th>
									<th>Email</th>
									</tr>\n";

								while($row=mysql_fetch_array($result))
								{
									echo "<tr>\n";
									echo "\n<td align=center><input type=\"checkbox\" name=\"deletes[]\" id=\"". $row['client_id'] . "\" value=\"". $row['client_id'] . "\" /></td>";
									echo "\n<td>". $row['client_id'] . "</td>";
									echo "\n<td>". $row['firstName'] . "</td>";
									echo "\n<td>". $row['lastName'] . "</td>";
									echo "\n<td>". $row['username'] . "</td>";
									echo "\n<td>". $row['email'] . "</td>";
									echo "\n</tr>";
								}
									echo "\n<td><input class=\"delete\" type=\"submit\" name=\"delbtn\" value=\"Delete\" /></td>";
									echo "\n</table>\n";
							}	
						?> 
					</fieldset>
				</form>
				<?php
					if(isset($_POST['delbtn'])) {
						// Loop through check boxes
						foreach ($_POST['deletes'] as $id){
							//  Delete  record from database
							mysql_query("DELETE FROM Client WHERE id='$id'"); 
							}
					}

					if(count($errors) > 0){
						echo "<fieldset><legend>Errors</legend>";
						echo "<div class=\"indent\"><br /><p class=\"bodyText\">The following errors occured with your client:</p></div><br />";
						echo "<div class=\"indent\"><p class=\"error\">";
						foreach($errors AS $error){
							echo $error . "\n";
						}
						echo "</p></div>";							
						//we use javascript to go back rather than reloading the page 
						// so the user doesn't have to type in all that info again.
					}
					//close DB
					mysql_close();
		?>


Link to comment
Share on other sites

That's a pretty cool trick.  Definately something I'll keep in my back pocket.

 

The problem was in the mysql query. 

 

I had

<?php mysql_query("DELETE FROM Client WHERE id='$id'");?> 

 

vice

 

<?php mysql_query("DELETE FROM Client WHERE client_id='$id'"); ?>

 

Next, how do I go about reloading the page without using header('Location: ../some.php/');?  The header function seem to conflict with a number of included/required .php files.  I thought about using JS onClick for the delete button but then the page would be redirected without completing the script to delete rows.  Any suggestions?? 

Link to comment
Share on other sites

I made the changes, however, the variables aren't passing info to the table.  I'm guessing syntax errors.  Here's the section of table having issues.

 

<table border="0" cellpadding="4" cellspacing="4" align="center">
  <tr> 
    <th align=center>Delete</th>
    <th>ID</th>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Username</th>
    <th>Email</th>
  </tr>

<?php while($row=mysql_fetch_array($result)){ ?>

  <tr>
    <td align=center><input type="checkbox" name= <?php "deletes[]" ?> id= <?php $row['client_id'] ?> value=<?php $row['client_id'] ?> /></td>
    <td><?php $row['client_id'] ?></td>
    <td><?php $row['firstName'] ?></td>
    <td><?php $row['lastName'] ?></td>
    <td><?php $row['username'] ?></td>
    <td><?php $row['email'] ?></td>
  </tr>

<?php } ?>

  <tr>
    <td><input class="delete" type="submit" name="delbtn" value="Delete" onclick="document.location = '../admin/client_list.php';"/></td>
  </tr>
</table>

Link to comment
Share on other sites

Well that's embarrasing.  I fixed the contents problem.  However, the page still isn't reloading on Delete.

 

<table border="0" cellpadding="4" cellspacing="4" align="center">
<tr>
<th align=center>Delete</th>
<th>ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Username</th>
<th>Email</th>
</tr>

<?php while($row=mysql_fetch_array($result)){ ?>

<tr>
<td align=center><input type="checkbox" name= <?php echo "deletes[]" ?> id= <?php echo $row['client_id'] ?> value=<?php echo $row['client_id'] ?> /></td>
<td><?php echo $row['client_id'] ?></td>
<td><?php echo $row['firstName'] ?></td>
<td><?php echo $row['lastName'] ?></td>
<td><?php echo $row['username'] ?></td>
<td><?php echo $row['email'] ?></td>
</tr>

<?php } ?>

<td><input class="delete" type="submit" name="delbtn" value="Delete" onclick="document.location = '../admin/client_list.php';"/></td>
</table>

Link to comment
Share on other sites

Because it's been a long day and I'm in desperate need of sleep.  Your fix worked!!  Thanks to all who helped.

 

Here's the finished script if anyone wants to see:

 

			<div id="col3_content" class="clearfix">
				<form action="client_list.php" action="slideshow_new.php" method="post" class="clearfix">
					<fieldset class="clearfix">
						<legend> Client List </legend>
							<?php
								// SQL query
								$query="SELECT * FROM Client";
								$result=mysql_query($query) or die('Query failed: ' . mysql_error());

								$num_rows = mysql_num_rows($result);

								// Error message for empty DB
								if ($num_rows == 0){
									$errors[] = "Database contains no client records.<br />
												<div class=\"bodyText\"><a href=\"../admin/client_new.php\">Add Client</a></div>";
								} else {
									// Print results in HTML
									// Number of records
									$num_rows = mysql_num_rows($result);
									echo "<p class=\"indent\">Client count = $num_rows</p>\n";
							?>
									<table border="0" cellpadding="4" cellspacing="4" align="center">
										<tr>
										<th align=center>Delete</th>
										<th>ID</th>
										<th>Firstname</th>
										<th>Lastname</th>
										<th>Username</th>
										<th>Email</th>
										</tr>
								<?php
									while($row=mysql_fetch_array($result)){
								?>
										 <tr>
										 <td align=center><input type="checkbox" name= <?php echo "deletes[]" ?> id= <?php echo $row['client_id'] ?> value=<?php echo $row['client_id'] ?> /></td>
										 <td><?php echo $row['client_id'] ?></td>
										 <td><?php echo $row['firstName'] ?></td>
										 <td><?php echo $row['lastName'] ?></td>
										 <td><?php echo $row['username'] ?></td>
										 <td><?php echo $row['email'] ?></td>
										 </tr>
								<?php
									}
								?>
										<td><input class="delete" type="submit" name="delbtn" value="Delete" /></td>
										</table>
							<?php
							}
							?> 
					</fieldset>
				</form>
				<?php
					if(isset($_POST['delbtn'])) {
						// Loop through check boxes
						foreach($_POST['deletes'] as $id){
							//  Delete  record from database
							mysql_query("DELETE FROM Client WHERE client_id='$id'"); 
						}
					}

					if(count($errors) > 0){
						echo "<fieldset><legend>Errors</legend>";
						echo "<div class=\"indent\"><br /><p class=\"bodyText\">The following errors occured with your client:</p></div><br />";
						echo "<div class=\"indent\"><p class=\"error\">";
						foreach($errors AS $error){
							echo $error . "\n";
						}
						echo "</p></div>";							
						//we use javascript to go back rather than reloading the page 
						// so the user doesn't have to type in all that info again.
					}
					//close DB
					mysql_close();
				?>
			</div>

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.