Jump to content

Problems executing code


Xianoth

Recommended Posts

If this is in the wrong spot, I apologize ahead of time....

 

I wrote a PHP script and I am trying to have it execute in a bash environment. I have verified that the PHP5-CGI is properly installed. However, when I try to execute this script, all it is doing is echoing back the full script to my terminal screen.

 

I know I must be missing something simple. Please help!  Code follows:

 

#!/usr/bin/php5-cgi -q

//Sets working directory
$dir = /var/www/test

//Scans the working directory and puts all information into an array
function select_files ($dir) {
        if (is_dir($dir)) {
         if ($handle = opendir($dir)) {
          $files = array();
           while (false !== ($file = readdir($handle))) {
            if (is_file($dir.$file) && $file != basename ($_server['PHP_SELF"])) $file [] = $file;
}
           closedir ($handle);
           if (is_array ($files)) sort ($files);
           return $files;
}
}
}

//Connect to database, assumes database and tables exist
mysql_connect ("localhost", "username", "password") or die(mysql_error());
mysql_select_db ("dbtest") or die(mysql_error());

//Insert directory array into Database
function insert_record ($name, $mod_date);
$sql = sprintf ("INSERT INTO dbtest SET filename = '%s', lastdate = '%s', location = '%s', $name, $mod_date, $fdir);
        if (mysql_query ($sql)) {
          return true;
        } else {
          return false;
}

 

 

Also, any advice on the code will be appreciated as well.

 

Link to comment
Share on other sites

Ok I have modded a few things in the script and I have gotten along a lil farther. I am now getting a parse error on line 38, which is the end of the script itself.  Not quite sure why this error is being flagged at me..

 

Here is the modified code:

 

 


#!/usr/bin/php5-cgi -q


//Sets working directory
$dir = '/var/www/test';

//Scans the working directory and puts all information into an array

function select_files ($dir) {
        if (is_dir($dir)) {
         if ($handle = opendir($dir)) {
          $files = array();
           while (false !== ($file = readdir($handle))) {
            if (is_file($dir.$file) && $file != basename ($_server['PHP_SELF"])) $file [] = $file;
}
           closedir ($handle);
           if (is_array ($files)) sort ($files);
           return $files;
}
}
}
<?php
//Connect to database, assumes database and tables exist
mysql_connect ("localhost", "root", "root1234") or die(mysql_error());
mysql_select_db ("dbtest") or die(mysql_error());

//Insert directory array into Database
function insert_record ($name, $mod_date){
$sql = sprintf ("INSERT INTO dbtest SET filename = '%s', lastdate = '%s', location = '%s', $name, $mod_date, $fdir);
        if (mysql_query ($sql)) {
          return true;
        } else {
          return false;
}
}
?>
end

 

I placed the php tags around the actual php code I am trying to use to insert the information into the database. Pointers and suggestions appreciated.

Link to comment
Share on other sites


#!/usr/bin/php5-cgi -q

<?php
//Sets working directory
$dir = '/var/www/test';

//Scans the working directory and puts all information into an array

function select_files ($dir) {
        if (is_dir($dir)) {
         if ($handle = opendir($dir)) {
          $files = array();
           while (false !== ($file = readdir($handle))) {
            if (is_file($dir.$file) && $file != basename ($_server['PHP_SELF"])) $file [] = $file;
}
           closedir ($handle);
           if (is_array ($files)) sort ($files);
           return $files;
}
}
}

//Connect to database, assumes database and tables exist
mysql_connect ("localhost", "root", "root1234") or die(mysql_error());
mysql_select_db ("dbtest") or die(mysql_error());

//Insert directory array into Database
function insert_record ($name, $mod_date){
$sql = sprintf ("INSERT INTO dbtest SET filename = '%s', lastdate = '%s', location = '%s', $name, $mod_date, $fdir);
        if (mysql_query ($sql)) {
          return true;
        } else {
          return false;
}
}
?>
end

 

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.