running script after clicking button
Moderator: General Moderators
running script after clicking button
hey ok i have this script in my comments.php page. everytime i visit mysite.com/scripts/comments.php it runs the script automatically. How can i make it so when i go to the comments.php page i can make it come up with a button and when i click it, it then runs the script that appears in that page instead of it running when i visit the page everytime
From what I understand you are trying to prevent blank entries in your comments.php
Try checking for POSTdata :
Try checking for POSTdata :
Code: Select all
if (isset($_POST['comments'])) {
// run the query here
}
else {
// display the form }I'm sorry but from what I understood from your post (without codeblade_922 wrote:no,
ok when i got to comments.php the script runs on its on. all i have in the comments.php page is the script.
I want a button so when i click it, it then runs the script on the comments.php page.
like astions said, could you post some code, will help the reader (and you) a lot more.
Code: Select all
<?php
/**
* Replace the terms in this array with the terms inside the comments you want to remove
*/
$searchterms = array('pharmacy', 'dating', '<span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>', 'badwords');
$conditions = array();
foreach($searchterms as $value)
$conditions[] = "`comment` LIKE '%{$value}%'";
$sql = "DELETE FROM `mos_akocomment` WHERE ".implode(" OR ", $conditions);
//
// connect to the db server and select db
//
$result = mysql_query($sql);
?>Thats the code on my comments.php page.
- MarK (CZ)
- Forum Contributor
- Posts: 239
- Joined: Tue Apr 13, 2004 12:51 am
- Location: Prague (CZ) / Vienna (A)
- Contact:
Code: Select all
<?php
if (isset($_GET["remove"])) {
/**
* Replace the terms in this array with the terms inside the comments you want to remove
*/
$searchterms = array('pharmacy', 'dating', '<span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>', 'badwords');
$conditions = array();
foreach($searchterms as $value)
$conditions[] = "`comment` LIKE '%{$value}%'";
$sql = "DELETE FROM `mos_akocomment` WHERE ".implode(" OR ", $conditions);
//
// connect to the db server and select db
//
$result = mysql_query($sql);
}
?>Code: Select all
<button type='button' onclick='location = "comments.php?remove";'>Remove it</button>
Last edited by MarK (CZ) on Mon Jul 24, 2006 7:53 am, edited 2 times in total.
This should work for you. Place the html above or below the PHP code. Untested..
Code: Select all
<form name="send" action="#" method="POST">
<input type="submit" name="submit" value="Execute" />
</form>
Code: Select all
<?php
if ((isset($_POST['submit'])) && ($_POST['submit'] == 'Execute'))
{
/**
* Replace the terms in this array with the terms inside the comments you want to remove
*/
$searchterms = array('pharmacy', 'dating', '<span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>', 'badwords');
$conditions = array();
foreach($searchterms as $value)
{
$conditions[] = "`comment` LIKE '%{$value}%'";
}
$sql = "DELETE FROM `mos_akocomment` WHERE ".implode(" OR ", $conditions);
//
// connect to the db server and select db
//
$result = mysql_query($sql);
}
?>I'm not sure what the problem is then.. Just check if there was a submission and if not, display the button.blade_922 wrote:um not sure.
See when i visit comments.php page it comes up blank page and runs script. I want it to NOT run script automatically and make button appear so when i click the button it runs script