Page 1 of 1

running script after clicking button

Posted: Mon Jul 24, 2006 7:30 am
by blade_922
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

Posted: Mon Jul 24, 2006 7:34 am
by thiscatis
From what I understand you are trying to prevent blank entries in your comments.php

Try checking for POSTdata :

Code: Select all

if (isset($_POST['comments'])) {

// run the query here
  } 

else {

// display the form }

Posted: Mon Jul 24, 2006 7:44 am
by blade_922
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.

Posted: Mon Jul 24, 2006 7:45 am
by Benjamin
Post your code please.

Posted: Mon Jul 24, 2006 7:47 am
by thiscatis
blade_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.
I'm sorry but from what I understood from your post (without code ;) ) was something that I was asking for earlier,
like astions said, could you post some code, will help the reader (and you) a lot more.

Posted: Mon Jul 24, 2006 7:47 am
by blade_922

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.

Posted: Mon Jul 24, 2006 7:48 am
by MarK (CZ)

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>

Posted: Mon Jul 24, 2006 7:50 am
by blade_922
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

Posted: Mon Jul 24, 2006 7:53 am
by Benjamin
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);
}
?>

Posted: Mon Jul 24, 2006 7:54 am
by thiscatis
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
I'm not sure what the problem is then.. Just check if there was a submission and if not, display the button.

Posted: Mon Jul 24, 2006 7:55 am
by MarK (CZ)
Editted my last post, got you wrong...
My own code from another topic :P

However, is it safe to show a button for deleting? I don't know what all you want to delete, maybe using a password would be better (maybe not, don't know the purpose of this).

Posted: Mon Jul 24, 2006 7:58 am
by Benjamin
MarK (CZ) wrote:However, is it safe to show a button for deleting?
Using a $_GET request to perform any action besides displaying data creates security issues.

Posted: Mon Jul 24, 2006 8:00 am
by blade_922
i used astions post and it worked. Its just a temporary piece of script i need to use to clean up some things.