running script after clicking button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

running script after clicking button

Post 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
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post 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 }
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Post your code please.
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post 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.
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post 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.
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post 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>
Last edited by MarK (CZ) on Mon Jul 24, 2006 7:53 am, edited 2 times in total.
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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);
}
?>
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post 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.
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post 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).
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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.
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post 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.
Post Reply