Jump to content

scottybwoy

Members
  • Posts

    532
  • Joined

  • Last visited

    Never

Posts posted by scottybwoy

  1. Yeah, thats great, cheers.  I realised that I did not need the for each so wrote it again similar to what you have done.

    What I am trying to do is create an array that is ready for javascript to come and collect in an AJAX fashion.  Do you know how javascript can read data for an array?  Am I on the right track, cheers for your help huggie
  2. Hi ppl,

    I'm trying to get a script to return an array ready for Ajax to pick it up, but at the mo it's not filling in an array at all, think it's got something to do with my foreach func.  Here's the code :
    [code]
    <?php
      function company_col()
      {
      $sql = "SELECT company FROM customers";
        $result = mssql_query($sql) or die("SQL Error selecting customers");

        while ($row = mssql_fetch_row($result))
        {
            $companies = array();
            foreach ($row as $value)
            {
                $companies[] = '"'.addslashes($value).'"';
            }

            $companies[] = "\t[".implode(",", $row)."]";
        }

        echo "$companies";
      }

    company_col();

    ?>
    [/code]
    Where am I going wrong? Cheers
  3. Cheers, I already have my login script and a session variable is stored and I know how to use echo, my problem is I have my header template included but I want that data from my php to go into a welcome message in my template.  Or is there no way to do that, sort of like post but the other way round.  Cheers I shud have thaught about client side java for the date.  Any more solutions to the prior question?
  4. Cheers Jenk, I think I've been following those rules, I just need to decipher now why my __consruct() is being run twice.  Any ideas as to what may be the cause.  I don't specifically call that function anywhere.  Just run NewClass = new Class;  And have another file being called that extends Class anything else do you know what what could do it?
  5. constants mainly and some variables, but I don't think my path is being set.
    Here's the config file :
    [code]
    <?php

        define('APP_DB', 'mri_sql');
        define('AUTH_DB_TBL', 'users');

    define('ROOT_PATH', $_SERVER['DOCUMENT_ROOT']);
    define('INTRANET_DIR', ROOT_PATH . '/database');
    define('SCRIPTS', INTRANET_DIR . '/scripts');
    define('CLASSES', INTRANET_DIR . '/classes');

    define('LIBS', INTRANET_DIR . '/library');
    define('PHPLIB_DIR', LIBS . '/php');
    define('JS_LIB_PATH', LIBS . '/js');

    define('PATH', CLASSES . ';' . SCRIPTS . ';' . LIBS);
    ini_set( 'include_path', ';' . PATH . ';' . ini_get('include_path'));

    define('TEMPLATE_DIR', INTRANET_DIR . '/templates');

    require_once 'constants.php';
    require_once $DEBUGGER_CLASS;
    // require_once $ERROR_HANDLER_CLASS;
    // require_once $USER_CLASS;
    // require_once $TEMPLATE_CLASS;

    //  And my database connection
    ?>
    [/code]

    But I just wanted to know that if was included once already shoud it be available accross the board?
  6. I'm using OOP concepts in php5.

    I have a main parent class, but above it i have all my constants and configs included in a seperate file like so :

    [code]
    <?php

    require_once 'config.inc.php';

    class PHPApplication {
        ....
    }
    ?>
    [/code]

    Later on in the file a call to another file occurs to display the page.  Within the called file is another class that extends the original but all my configs are gone.  Is there a better way to have my configs included once and be available to all my files?
    Thanks
  7. Theres another bug in your site E-Worldpeace.com great ideas, keep it up:

    Could not delete old search id sessions

    DEBUG MODE

    SQL Error : 1054 Unknown column 'search_time' in 'where clause'

    DELETE FROM phpbb_search_results WHERE search_time < 1159518767

    Line : 657
    File : search.php
  8. Hmm,  What I am trying to implement is built into my framework structure, that only has a few client executable scripts that then go off and include other scripts into the original script, depending on their autorisation level.  That way the user wouldn't even need to put in the .htaccess pass.  I think this is similar to what you want, but I'm going down the OOP route.

    Structure -->
        |
        +-classes
        +-scripts
        +-templates
        +-libs
        +-httpd
        |    +-images
        |    +style.css
        |    +index.php

    So all they have access to is index.php images and the style sheet, so index just includes another application backbone file that sorts out all the pages and templates all done behind closed doors based on the authentication you set.  Good Luck
  9. Hi All,

    What is a Resource ID?  I see them popped up here and there and don't really know what they are?  I searched on the net and found no meaning, once again they popped up with no explanation.  So I thaught some of you clever people would know.  Are they what php uses to locate a result of an SQL query, or are they bad?

    Thanks in advance
  10. Re-wrote the function, got it working
    [code]
    <?php
    function userLevel($user)
    {
    $this->appCon();

    $sql = mssql_query("SELECT level FROM users WHERE uNAME = '" . $user . "'");

    if (!row == mssql_fetch_row($sql))
    {
    die ("You do not have any access");
    } else {
    $user_level = mssql_result($sql, 0, 0);
    }

    return $user_level;
    }
    ?>
    [/code]

    Thanks to all who helped
  11. Hi Shoz,

    Yeah I tried that before and I get a diffrent error about a row offset :

    PHP Warning: mssql_result() [function.mssql-result]: Bad row offset (0) in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 51

    However, I have used this function before and never put 'field' perameters in and it has worked.  As it is only returning a single cell key I don't see why it needs these perameters, well from what I can see ,0,0 represent row1, column1, which is just the cell returned.  Please note again that basically it should find no value at all, should it be returning these kinds of messages?

    Thanks
  12. *** PROBE ***  I understand the perameters, i.e 'level' = the column, 'users' = the table, '$user' = the uNAME column.  So it seems to me the right parameter count.  This is my fuction that calls userLevel :
    [code]
    <?php
    function __construct()
    {
    echo $this->getName();
    echo "<BR/>";
    echo $this->authorise($this->getName);
    echo "<BR/>";
    echo $this->userLevel($this->getName);
    }
    ?>
    [/code]
    And the name passed in does not exist in the database at all.  So is it meant to give that error?
  13. OK This is "sort of" working for me now :
    [code]
    <?php
    function userLevel($user)
    {
    $this->appCon();

    $sql = mssql_query("SELECT level FROM users WHERE uNAME = '" . $user . "'");
    $user_level = mssql_result($sql,0);

    return $user_level;
    }
    ?>
    [/code]
    Now back to my first question, how does mssql_result work?

    I now get this error:

    PHP Warning: Wrong parameter count for mssql_result() in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 51

    Thanks for ya patience

    By the way Wildteen, when I used ur suggestion I got syntax errors all over the place.
  14. lol thanks,

    I thaught mssql_result returned the value of the one cell I was after, cheers for pointing out the 2 query issue, stupid me. ;)

    But I tried both your suggestion and I get an error by the = :

    PHP Warning: mssql_query() [function.mssql-query]: message: Line 1: Incorrect syntax near '='. (severity 15) in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 43 PHP Warning: mssql_query() [function.mssql-query]: Query failed in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 43 PHP Warning: mssql_fetch_assoc(): supplied argument is not a valid MS SQL-result resource in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 44

    I tried it both ways round like in my first post, no joy.  Any Suggestions
  15. Hi Again,

    I have this small function to get a user ID from a database :

    [code]
    <?php
    function userLevel($user)
    {
    $this->appCon();

    $user_id = mssql_result("SELECT userId FROM users WHERE uNAME = $user");
    $user_level = mssql_result("SELECT level FROM users WHERE userId = " . $user_id);

    return $user_level;
    }
    ?>
    [/code]

    And I get this error :

    PHP Warning: Wrong parameter count for mssql_result() in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 51 PHP Warning: Wrong parameter count for mssql_result() in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 52

    Line 51/2 are the queries, but basically both $vars don't exist in the database it's for a test so should these errors occur?
  16. Right I have this code nearly working now, but it fails on this query :
    [code]
    <?php
    function authorise($user)
    {

    mssql_select_db(APP_DB) or die("could not select database");

    if ($user = !null)
    {
    if (mssql_query("SELECT USER_ID FROM users WHERE uNAME = $user") = TRUE)
    {
    echo "You are not entered in the Database, please see the Administrator";
    exit;
    } else if (mssql_query("SELECT USER_ID FROM users WHERE uNAME = $user") = FALSE) {
    echo "Error upon Query, contact your administrator";
    exit;
    } else {
    $success == TRUE;
    }

    } else {
    $success == FALSE;
    }

    return $success;
    }
    ?>
    [/code]
    Basically I have ommited my username for the database on purpose for it to fail on this query to bring up the message in the first clause.  But instead I get this error :

    PHP Fatal error: Can't use function return value in write context in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 35

    Can I not have = TRUE, or what is it saying.  Thanks
  17. Right, now I've changed it around a bit and now it's not connecting to the database, here's the code :
    [code]
    <?php

      require_once 'config.inc.php';

      class PHPApplication {

        function getName()
        {
    $domain_user = explode("\\", $_SERVER['LOGON_USER']);
    $user = $domain_user[1];

    return $user;
    }

    function authorise($user)
        {
    global $CONNECTION;

    mssql_select_db($APP_DB) or die("could not select database");

    if ($user = !null)
    {
    if (!mssql_query("SELECT USER_ID FROM users WHERE uNAME = {$user}", $CONNECTION))
    {
    echo "You are not entered in the Database, please see the Administrator";
    exit;
    } else {
    $success == TRUE;
    }
    } else {
    $success == FALSE;
    }
    return $success;

    if ($success = TRUE)
    {
    $msg = "OK Your in";
    } else {
    $msg = "Get out";
    }
    echo $msg;
    }

    function run()
    {
    global $CONNECTION;

    $CONNECTION = mssql_connect($INTRANET_DB_URL) or die("Could not connect to Database");

    echo $this->getName();
    echo "<BR/>";
    echo "<BR/>";
    echo $this->authorise($user);


    }

    function userLevel()
    {
    global $CONNECTION;

    $query = "SELECT TYPE FROM users WHERE USER_ID = $user_id";
    $user_level = mssql_result($query, $CONNECTION);
    }

      }

    $thisApp = new PHPApplication();

    $thisApp->run();

    ?>
    [/code]

    Is that because the connection is being droped by the time it calls the next function?

    here's the error :

    could not select databasePHP Warning: mssql_select_db() [function.mssql-select-db]: Unable to select database: in C:\Inetpub\wwwroot\database\classes\mri_central.php on line 28

    Thank ppl
  18. Hmm OK that makes sense, I thaught that you could define a variable within the $this->  I looked it up in the php pages and couldn't find anything on it so could anyone explain how $this-> and $foo works and are they confined to classes or could you pass me into the right direction?

    Also sasa i set up $connected and it still didn't do anything, thanks tho.
  19. Ok I've made a class and put some functions in itand it's not returning what I want have a quick read first :
    [code]
    <?php

      require_once 'config.inc.php';

      class PHPApplication {

        function getName()
        {
    $domain_user = explode("\\", $_SERVER['LOGON_USER']);
    $user = $domain_user[1];

    return $user;
    echo $user;
    }

    function connect()
          {
            global $CONNECTION;

    $CONNECTION = mssql_connect($INTRANET_DB_URL);
    $this->connected == TRUE or die;
    $this->connected == FALSE;
    mssql_select_db($APP_DB);
    $this->connected == TRUE or die;
    $this->connected == FALSE;

    echo $connected;
    }

    function authorise($user)
        {
    global $CONNECTION;
    echo $user;

    if ($user == !null)
    {
    if (!mssql_query("SELECT USER_ID FROM users WHERE uNAME = {$user}", $CONNECTION))
    {
    echo "You are not entered in the Database, please see the Administrator";
    exit;
    } else {
    $success == TRUE;
    }
    } else {
    $success == FALSE;
    }
    return $success;

    if ($success = TRUE)
    {
    $msg = "OK Your in";
    } else {
    $msg = "Get out";
    }
    echo $msg;
    }

    function run()
    {
    echo $this->getName();
    echo "<BR/>";
    echo $this->connect();
    echo "<BR/>";
    echo $this->authorise();
    }
      }

    $thisApp = new PHPApplication();

    $thisApp->run();

    ?>
    [/code]
    Now all it echo's is my user name, so is $connected even instantiated and I don't know why $msg is being displayed.  Can someone point out where I'm going wrong and also if I could have just echoed $success to see TRUE/FALSE?  Thanks in advance
×
×
  • 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.