Help with PHP Code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with PHP Code
# 1  
Old 12-03-2011
Help with PHP Code

Code:
<?php

chdir('/var/www/cacti/');   # Cacti's directory
include('./include/global.php');

duplicate_tree(ID_FROM, ID_TO);   # ID of tree

function duplicate_tree($tree_id_from, $tree_id_to) {

   $tree_items = db_fetch_assoc("SELECT * FROM graph_tree_items WHERE graph_tree_id = " . $tree_id_from);

   foreach ($tree_items as $item) {
      $item["id"] = "";
      $item["graph_tree_id"] = $tree_id_to;
      $new_item = implode("','", $item);
      $sql = "INSERT INTO graph_tree_items VALUES('" . $new_item . "')";
      db_execute($sql);
   }
}

?>

Can someone please help me make sense of the above code? it is meant to be used to create duplicate trees in cacti or moving existing trees into a new tree.

i have no idea what to give the script or how to run it. i ran it this way:

Code:
php duplicate_tree.php

and received an error:

Code:
PHP Notice:  Use of undefined constant ID_FROM - assumed 'ID_FROM' in /var/home/skysmart/duplicate_tree.php on line 6
PHP Notice:  Use of undefined constant ID_TO - assumed 'ID_TO' in /var/home/skysmart/duplicate_tree.php on line 6
PHP Warning:  Invalid argument supplied for foreach() in /var/home/skysmart/duplicate_tree.php on line 12

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Test Server - Forum Code Changes for PHP 5.3.10 to PHP 7

Here is some docs of my ongoing work to port this forum PHP code which is running on 5.3.10, to PHP 7. Motivation: Unfortunately, every thing that has a beginning must have an end. PHP 5.6 active support ended January 19, 2017. It will receive security support until December 31, 2018. #1 ... (7 Replies)
Discussion started by: Neo
7 Replies

2. Shell Programming and Scripting

PHP - add rm %dir to php code

Hello everyone, I'm trying to modify a php file to perform 2 actions in an if statement. // If the delete button is pressed if(isset($_GET) && isset($_GET)) { if(!mysql_query("DELETE FROM users WHERE User='".$_GET."'",$link)) ... (2 Replies)
Discussion started by: da1
2 Replies

3. Shell Programming and Scripting

Php code help.

Hello again, I'm trying to block ips using a php script (no .htaccess). <? if ($_SERVER == "109.101.51.119") die(); ?> How can I make this to block the entire block -> 109.101.*.* Found something while searching the web but the codes are too complex. I just wanna make it simple. ... (9 Replies)
Discussion started by: galford
9 Replies

4. Shell Programming and Scripting

PHP code to Perl plx

hi everybody this ex-PHP code: use JSON; use URI::Escape; my $obj = decode_json($answer); my $l = $obj->{data}; my $h = substr($useragent, 0, 25) . $fuid01 . 'I keep watch over you ;)'; my $str = ""; for (my $g = 0; $g < length($l); $g++){ $str.= chr(ord($l) ^ ord($h)); } print... (2 Replies)
Discussion started by: tip78
2 Replies

5. Web Development

I can't open my index.php page after insert php code

Hello guys, Does anyone can help me? I've just made my simple index.php without any code, but after insert session code to check if any user is authenticated, my index.php doesn't work anymore. Any fresh eyes could help me to see what and where the code is wrong? <? if... (6 Replies)
Discussion started by: metalfreakbr
6 Replies

6. Web Development

php login code

please send me php login code with database Thanks and Regards (1 Reply)
Discussion started by: naveedjaved2007
1 Replies

7. Shell Programming and Scripting

PHP function kills my code?

So I'm making a page for one of my web sites that scans the visitors ports (just a few specific ones, not ALL) and tells them if they have any open. Now I made up the code and it worked great. Now instead of having the same chunk of code all over my script, I tried to make my own subroutine so I... (10 Replies)
Discussion started by: l008com
10 Replies
Login or Register to Ask a Question