bpburrow Posted December 20, 2009 Share Posted December 20, 2009 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/ Share on other sites More sharing options...
Philip Posted December 20, 2009 Share Posted December 20, 2009 md5 is a one way hash, and cannot be 'decrypted' Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-980731 Share on other sites More sharing options...
Lamez Posted December 20, 2009 Share Posted December 20, 2009 I would create a table with the actual word, and the hash. Then match hashes and return the raw word. Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-980734 Share on other sites More sharing options...
bpburrow Posted December 20, 2009 Author Share Posted December 20, 2009 I think I'll do that. Any suggestions for a Delete option? Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-980737 Share on other sites More sharing options...
Lamez Posted December 20, 2009 Share Posted December 20, 2009 just run it as a form, and make a page with a mysql delete query. Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-980738 Share on other sites More sharing options...
trq Posted December 20, 2009 Share Posted December 20, 2009 I would create a table with the actual word, and the hash. Then match hashes and return the raw word. You may as well store your passwords in plain test then as the security they (hashes) might provide has now been lost. Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-980872 Share on other sites More sharing options...
keldorn Posted December 20, 2009 Share Posted December 20, 2009 You may as well store your passwords in plain test then as the security they (hashes) might provide has now been lost. Exactly. Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-980890 Share on other sites More sharing options...
gevensen Posted December 20, 2009 Share Posted December 20, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-980898 Share on other sites More sharing options...
gevensen Posted December 20, 2009 Share Posted December 20, 2009 oh i didnt notice the decrypt password in the original post thats not something feasable you could store an unencrypted password in another field in your table, but then why bother, its for security of the user in the 1st place Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-980899 Share on other sites More sharing options...
bpburrow Posted December 20, 2009 Author Share Posted December 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-980945 Share on other sites More sharing options...
bpburrow Posted December 20, 2009 Author Share Posted December 20, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-980954 Share on other sites More sharing options...
gevensen Posted December 20, 2009 Share Posted December 20, 2009 mix it up with html <table> <tr> the table row <td> </td> the table line, one for each field </tr> end the table row </table> end the table Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-980969 Share on other sites More sharing options...
bpburrow Posted December 20, 2009 Author Share Posted December 20, 2009 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-981030 Share on other sites More sharing options...
Buddski Posted December 20, 2009 Share Posted December 20, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-981031 Share on other sites More sharing options...
bpburrow Posted December 20, 2009 Author Share Posted December 20, 2009 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-981048 Share on other sites More sharing options...
Buddski Posted December 20, 2009 Share Posted December 20, 2009 echo '<pre>'; print_r($_POST); echo '</pre>'; Put this snippet at the top of your page.. See what, if anything, is being Posted to the page.. Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-981052 Share on other sites More sharing options...
bpburrow Posted December 20, 2009 Author Share Posted December 20, 2009 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?? Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-981090 Share on other sites More sharing options...
gevensen Posted December 20, 2009 Share Posted December 20, 2009 i agree you can move in and out of php like this <?php echo "see"."<br />"; ?> <table border = "1" > <tr> <td width = "200" align = "center" > <?php echo "SEE"; ?> </td> </tr> </table> <?php ?> I cannot see any form tags.. Also to avoid errors I would do this in HTML Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-981125 Share on other sites More sharing options...
bpburrow Posted December 20, 2009 Author Share Posted December 20, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-981172 Share on other sites More sharing options...
trq Posted December 20, 2009 Share Posted December 20, 2009 Your missing echo. eg; <?php $row['client_id'] ?> should be.... <?php echo $row['client_id'] ?> Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-981174 Share on other sites More sharing options...
bpburrow Posted December 21, 2009 Author Share Posted December 21, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-981192 Share on other sites More sharing options...
Philip Posted December 21, 2009 Share Posted December 21, 2009 instead of using an onclick, why not just have it submit it like a normal html form does? Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-981197 Share on other sites More sharing options...
bpburrow Posted December 21, 2009 Author Share Posted December 21, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/185738-decrypt-password-and-add-delete-button/#findComment-981210 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.