Jump to content

scottybwoy

Members
  • Posts

    532
  • Joined

  • Last visited

    Never

Posts posted by scottybwoy

  1. I am still having trouble with this query below : (Please Help!!!)

    [code]
    <?php

    require_once('constants.php');

    $DEBUG = 0;

    $SESS_LIFE = get_cfg_var("session.gc_maxlifetime");

            function sess_open($save_path, $session_name) {
              return true;
            }

            function sess_close() {
              return true;
            }

            function sess_read($key) {
                    global $DEBUG, $SESS_LIFE;

    $statement = "SELECT * FROM sessions WHERE sesskey = '$key' AND expiry > " . time();
                    $result = mssql_query($statement) or die ('Query failed.');  // This is Line 21

                    if ($DEBUG) echo "sess_read: $statement <br>result: $result<br>";
                   
    if ($result) {
    $row = mssql_fetch_assoc($result);
    return $row['value'];
    }
    return false;
            }
    ?>
    [/code]

    Also posted everything above it to show how lib.session_handler.php is being run.
    The Error I am getting is this one here :

    Query failed.PHP Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'sessions'. (severity 16) in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 21 PHP Warning: mssql_query() [function.mssql-query]: Query failed in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 21

    I have tried a number of things and you can find more details by [url=http://www.phpfreaks.com/forums/index.php/topic,105051.0.html]going here[/url]
    I have been on this problem for over a week now and it is doing my head in  ???

    As you can find from the previous post that it is now using one connection as shown here :

    [code]
    <?php

    function connect()
          {

            // connect to the database

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

    ?>
    [/code]

    As found in file class.PHPApplication.php
    These constants are defined here in config.inc.php :

    [code]
    <?php

        $AUTH_DB_USERNAME     = 'user';
        $AUTH_DB_PASSWD       = 'pass';
        $AUTH_DB_HOST = 'localhost';
        $AUTH_DB_NAME = 'mri_sql';
        $AUTH_DB_TBL                  = 'users';

    $INTRANET_DB_URL = '"' . $AUTH_DB_HOST . '"' . ',' . '"' . $AUTH_DB_USERNAME . '"' . ',' . '"' . $AUTH_DB_PASSWD . '"';
    $AUTH_DB_URL        = $INTRANET_DB_URL;
    $USER_DB_URL        = $INTRANET_DB_URL;
    $APP_DB_URL = $INTRANET_DB_URL;

    // some other code

    //  require_once 'DB.php';
     
      require_once 'constants.php';
      require_once $APPLICATION_CLASS;
      require_once $ERROR_HANDLER_CLASS;
      require_once $AUTHENTICATION_CLASS;
    //  require_once $DBI_CLASS;
    //  require_once $THEME_CLASS;
    //  require_once $THEME_TEMPLATE_CLASS;
      require_once $USER_CLASS;
      require_once $TEMPLATE_CLASS;

    ?>
    [/code]

    This config file is called by the Application config files.  In this case login.conf.php.  Which is called by login.php, the Application class that extends class.PHPApplication.php, the backbone of my project which connects the database as seen above.

    I hope there is enough info here and on the [url=http://www.phpfreaks.com/forums/index.php/topic,105051.0.html]other page[/url] linked to help you help me solve this, I can't move on untill this is sorted. Thanks
  2. OK this is my code now :
    [code]
    <?php

    $domain_user = explode("\\", $_SERVER['LOGON_USER']);
    $user = $domain_user[1] . "<br />";
    echo $user;

    $AUTH_DB_NAME = 'mri_sql';
    $AUTH_DB_TBL    = 'users';

    mssql_connect("localhost", "1433", "user", "pass") or
    die("cannot connect");
    mssql_select_db("$AUTH_DB_NAME") or
    die ("cannot connect to database");

    $query = "SELECT * FROM users where uName = '$user' AND active = 1";
    $query = stripslashes($query);
    $result = mssql_query($query);
    while($row = mssql_fetch_assoc($result)){
    if ($row[uName] == $user)
    $idImLookingFor = $row['user_id'];
    }

    print_r($row);
    ?>
    [/code]

    Which output's :

    technical
  3. HuggieBear is right change your websites hit's table to this :

    CREATE TABLE `websites_hits` (
      `members_id` varchar(15) NOT NULL default '0',
      `websites_id` bigint(15) NOT NULL default '0',
      `websites_hits` bigint(15) NOT NULL default '0'
    ) TYPE=MyISAM;

    INSERT INTO `websites_hits` VALUES (1, 1, 0);

    Then create relationships between member_id and websites_is to your websites_hits table then use :

    "SELECT websites_id FROM websites_hits WHERE members_id = '$member' AND website_hits = 0"
  4. maybe, that didn't return anything except technical.  How am I supposed to know the row number ($row['yourow']) when what I am after is the user ID from the row containing the user name.

    Tried both and they return the same, only the user name

    Thanks though
  5. Yep it is a constant, here's the code :
    [code]
    <?php

        $AUTH_DB_USERNAME     = 'user';
        $AUTH_DB_PASSWD       = 'pass';
        $AUTH_DB_HOST = 'localhost';
        $AUTH_DB_NAME = 'mri_sql';
        $AUTH_DB_TBL                  = 'users';

    $INTRANET_DB_URL = '"' . $AUTH_DB_HOST . '"' . ',' . '"' . $AUTH_DB_USERNAME . '"' . ',' . '"' . $AUTH_DB_PASSWD . '"';
    $AUTH_DB_URL        = $INTRANET_DB_URL;
    $USER_DB_URL        = $INTRANET_DB_URL;
    $APP_DB_URL = $INTRANET_DB_URL;

    // Which also calls these at the bottom

    //  require_once 'DB.php';
     
      require_once 'constants.php';
      require_once $APPLICATION_CLASS;
      require_once $ERROR_HANDLER_CLASS;
      require_once $AUTHENTICATION_CLASS;
    //  require_once $DBI_CLASS;
    //  require_once $THEME_CLASS;
    //  require_once $THEME_TEMPLATE_CLASS;
      require_once $USER_CLASS;
      require_once $TEMPLATE_CLASS;

    ?>
    [/code]

    Found in config.inc.php which is loaded from the conf files of my classes that extend the class.PHPApplication.php file.  In this case what is happening is :

    index.php is executed which just redirects to home.php ->
    home.php loads home.conf.php and extends class.PHPApplication.php ->

    If user does not have a session home.php relies on class.PHPApplication.php to redirect to login.php

    login.php loads login.conf.php and extends class.PHPApplication.php ->

    Here the username is validated and those credetials are used to create a session by lib.session_handler.php -- this is where I run into problems.

    I tried what you said and took out the quotes but did not make a difference.  I hope there is enough info here for you to help me, thanks.
  6. I have this code here :
    [code]
    <?php

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

    $AUTH_DB_NAME = 'mri_sql';
    $AUTH_DB_TBL    = 'users';

    mssql_connect("localhost,1433", "user", "pass", "") or
    die("Failed Connection");
    mssql_select_db("$AUTH_DB_NAME") or
    die ("cannot connect to database");

    $result = mssql_query("SELECT USER_ID FROM users WHERE uNAME = '" . $user . "' AND ACTIVE = '1'");

    echo $result;

    ?>
    [/code]

    And I get this result :

    technicalResource id #2

    Shouldn't I get :

    technical3

    technical being my username and 3 being my ID
  7. Hi all,

    Am working on a database project for my company and have pretty much everything set up.  However I am unsure whether a relationship is needed here.  Let me explain :

    We have different types of customers and have a table  holding these that is related to the customers table.  When a customer makes a sale the cust ID is related to that sale carrying with it the customer type.  Then our products are given as a different price depending on their type.  Do I need a relationship between the Cutomers table, value type to the Product table, value type?

    Does this make sense, the Sales table is connected to the Product table via Purchase Order key.
  8. Ok I tottaly changed my query to "SELECT * FROM users" and it brings up the same Error Msg, that users is an Invalid Object.

    But it must have connected to that table before for authentication otherwise it would not execute this far.
    Where could this problem lie.

    Would it tell me if there was not a connection to this Database if it droped it before executing this script?
  9. Hi all,

    Am working on a database project for my company and have pretty much everything set up.  However I am unsure whether a relationship is needed here.  Let me explain :

    We have different types of customers and have a table  holding these that is related to the customers table.  When a customer makes a sale the cust ID is related to that sale carrying with it the customer type.  Then our products are given as a different price depending on their type.  Do I need a relationship between the Cutomers table, value type to the Product table, value type?

    Does this make sense, the Sales table is connected to the Product table via Purchase Order key.
  10. [quote author=php link=the manual]
    Autoloading Objects

    Many developers writing object-oriented applications create one PHP source file per-class definition. One of the biggest annoyances is having to write a long list of needed includes at the beginning of each script (one for each class).

    In PHP 5, this is no longer necessary. You may define an __autoload function which is automatically called in case you are trying to use a class which hasn't been defined yet. By calling this function the scripting engine is given a last chance to load the class before PHP fails with an error.
    [/quote]

    Too much for me to help you out, but this may, also look at class abstraction, may point out an impossibility for what you want to do, but least you'll know to find another way round it. ;)
  11. sessTbl is definately the right capitalisation, thats how I usually name things.  Sort of using a Framework package, what I am doing is using a tutorial book which has a similar project that I am trying to do, although it has more features than I need, so I'm trying to slim it down.  It used PEAR, however I don't need the database abstraction layer so I'm trying to take it out.  I'll post both versions so you can see the differences :

    [code]
    <?php

    // my edited version

    require_once('constants.php');

    $DEBUG = 0;

    $SESS_LIFE = get_cfg_var("session.gc_maxlifetime");

            function sess_open($save_path, $session_name) {
              return true;
            }

            function sess_close() {
              return true;
            }

            function sess_read($key) {
                    global $DEBUG, $SESS_LIFE;

    $statement = "SELECT value FROM sessTbl WHERE sesskey = '$key' AND expiry > " . time();
                    $result = mssql_query($statement) or die ('Query failed.');

                    if ($DEBUG) echo "sess_read: $statement <br>result: $result<br>";
                   
    if ($result) {
    $row = mssql_fetch_assoc($result);
    return $row['value'];
    }
    return false;
            }

            function sess_write($key, $val) {
                    global $SESS_LIFE;

                    $expiry = time() + $SESS_LIFE;
                    $value = addslashes($val);

                    $statement = "INSERT INTO sessTbl VALUES ('$key', $expiry, '$value')";
                    mssql_query($statement) or die ('Query failed.');

                    if ($DEBUG) echo "sess_write: $statement <br>result: $result<br>";

                    if (! $result) {
                            $statement = "UPDATE sessTbl SET expiry = $expiry, value = '$value' " .
                                  "WHERE sesskey = '$key' AND expiry > " . time();
                            mssql_query($statement) or die ('Query failed.');
                    }

                    return $result;
            }

            function sess_destroy($key) {

                    $statement = "DELETE FROM sessTbl WHERE sesskey = '$key'";
                    $result = mssql_query($statement);
                    if ($DEBUG) echo "sess_destroy: $statement <br>result: $result<br>";

                    return $result;
            }

            function sess_gc($maxlifetime) {

                    $statement = "DELETE FROM sessTbl WHERE expiry < " . time();
                    $qid = mssql_query($statement);
                    if ($DEBUG) echo "sess_gc: $statement <br>result: $result<br>";

                    return 1;
            }

            session_set_save_handler(
                    "sess_open",
                    "sess_close",
                    "sess_read",
                    "sess_write",
                    "sess_destroy",
                    "sess_gc");
    ?>
    [/code]

    The original version

    [code]
    <?php
    require_once('constants.php');
    require_once('class.DBI.php');
    require_once 'DB.php';

    $DEBUG = 0;

    $DB_URL = "mssql://user:pass@localhost:/sessions";

    $dbi =  new DBI($DB_URL);

    $SESS_LIFE = get_cfg_var("session.gc_maxlifetime");

            function sess_open($save_path, $session_name) {
              return true;
            }

            function sess_close() {
              return true;
            }

            function sess_read($key) {
                    global $dbi, $DEBUG, $SESS_LIFE;

                    $statement = "SELECT value FROM sessions WHERE " .
                          "sesskey = '$key' AND expiry > " . time();

                    $result = $dbi->query($statement);

                    if ($DEBUG) echo "sess_read: $statement <br>result: $result<br>";
                    $row = $result->fetchRow();
                    if ($row) {
                      return $row->value;
                    }

                    return false;
            }

            function sess_write($key, $val) {
                    global $dbi, $SESS_LIFE;

                    $expiry = time() + $SESS_LIFE;
                    $value = addslashes($val);

                    $statement = "INSERT INTO sessions VALUES ('$key', $expiry, '$value')";
                    $result = $dbi->query($statement);

                    if ($DEBUG) echo "sess_write: $statement <br>result: $result<br>";

                    if (! $result) {
                            $statement = "UPDATE sessions SET expiry = $expiry, value = '$value' " .
                                  "WHERE sesskey = '$key' AND expiry > " . time();
                            $result = $dbi->query($statement);
                    }

                    return $result;
            }

            function sess_destroy($key) {
                    global $dbi;

                    $statement = "DELETE FROM sessions WHERE sesskey = '$key'";
                    $result = $dbi->query($statement);
                    if ($DEBUG) echo "sess_destroy: $statement <br>result: $result<br>";

                    return $result;
            }

            function sess_gc($maxlifetime) {
                    global $dbi;

                    $statement = "DELETE FROM sessions WHERE expiry < " . time();
                    $qid = $dbi->query($statement);
                    if ($DEBUG) echo "sess_gc: $statement <br>result: $result<br>";

                    return 1;
            }

            session_set_save_handler(
                    "sess_open",
                    "sess_close",
                    "sess_read",
                    "sess_write",
                    "sess_destroy",
                    "sess_gc");
    ?>
    [/code]

    There is one file called class.PHPApplication.php which is like the central backbone to all the other areas of the application, near the beginning it has a require_once for lib.sessions_handler.php -- the file I'm having trouble with.  class.PHPApplication.php also connects to the database via this function :
    [code]
    <?php

    function connect()
          {

            // connect to the database

    mssql_connect($INTRANET_DB_URL);
    $this->connected == TRUE or die;
      $this->connected == FALSE;
    mssql_select_db("$AUTH_DB_TBL");
    $this->connected == TRUE or die;
    $this->connected == FALSE;
      }

    ?>
    [/code]

    Thanks again for your time
  12. By I mean it didn't work, it just gives the same Error, which suggests it's not a connection problem but maybe something to do with the query.  Please note I have tried using both the $statement variable and the actual $statement string, both recieve the same error and it appears that I don't have this built in function of mssql_error() as it now returns this error :

    PHP Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'sessTbl'. (severity 16) in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 21 PHP Warning: mssql_query() [function.mssql-query]: Query failed in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 21 PHP Fatal error: Call to undefined function mssql_error() in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 21

    By the way am using Windows 2k Server with IIS 5 and php 5.1.4
  13. [quote author=scottybwoy link=topic=105051.msg420659#msg420659 date=1156341435]
    I changed sessions to sessTbl
    [/quote]

    Thanks for clearing up the [] definition.  But why am I recieving this error.  I have two databases one that has all the gubbins for my project and one called sessions with just one table called sessTbl with 3 columns sessKey, expiry and value.  At the top of lib.session_handler.php I have the database connection like so :

    [code]
    <?php

    require_once('constants.php');
    //require_once('class.DBI.php');

    $DEBUG = 0;

    //$DB_URL = "mssql://user:pass@localhost:/sessions";

    mssql_connect("localhost", "user", "pass") or
    die("Could not connect to database");
    mssql_select_db("sessions") or
    die("Could not select database");

    //$dbi =  new DBI($DB_URL);

    $SESS_LIFE = get_cfg_var("session.gc_maxlifetime");

    ?>
    [/code]

    Then below are my functions.  Will this overide any original connections i.e my other database, which is used for login/authentication.  If not would it be viable to just have sessTbl in my other database and not have two?  As if it is searching for that tbl in the wrong database that could be why, it returns an invalid object.
  14. I changed sessions to sessTbl as the database and table were both called sessions, and I thaught it may be selecting the database instaed of the table so I changed the table name and ammended the code to clarify that that was not where the problem laid.  I done this as I gathered that is what it mean by Object.

    do I need any of these : [, resource link_identifier [, int batch_size]] , for my query to work?
    If so what do they mean, how do I find out what goes in there, again excuse my ignorance, I apreciate your help.
  15. Yes your right, I had just worked it out, I had read the MS SQL functions in THE MANUAL but get a little confused as to what some words mean, I'm new to programming and do it out of funtion rather than fashion, so please forgive my ignorance.  I worked it out just by playing around.

    arguments - what are they in accordance to my code above please?

    I thaught that mssql_result() queried the database and then returned the single value requested and that mssql_query returned either TRUE or FALSE, which is why I hadn't used it.  Then I realised I was wrong, mssql_query() only returns FALSE if it fails.

    How does mssql_query() present itself to $result in my example, would it be an associative array? i.e $result[value] = whatever_value ?

    In the example above there would only be one value as $key is a unique session key so would not break "return $row['value'];"

    Is this correct understanding?

    But now I get these Errors:

    PHP Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'sessTbl'. (severity 16) in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 49 PHP Warning: mssql_query() [function.mssql-query]: Query failed in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 49 PHP Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'sessTbl'. (severity 16) in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 56 PHP Warning: mssql_query() [function.mssql-query]: Query failed in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 56

    from this :

    [code]
    <?php

    function sess_write($key, $val) {
                    global $SESS_LIFE;

                    $expiry = time() + $SESS_LIFE;
                    $value = addslashes($val);

                    $statement = "INSERT INTO sessTbl VALUES ('$key', $expiry, '$value')";
                    $result = mssql_query($statement);  // this is line 49

                    if ($DEBUG) echo "sess_write: $statement <br>result: $result<br>";

                    if (! $result) {
                            $statement = "UPDATE sessTbl SET expiry = $expiry, value = '$value' " .
                                  "WHERE sesskey = '$key' AND expiry > " . time();
                            $result = mssql_query($statement); // this is line 56
                    }

                    return $result;
            }

    ?>
    [/code]

    Assuming that the first posted code has been amended in the same fashion.  I thaught it read the table first to see if it needed to write a session, if that is the case it would know that the object sessTbl does exist.  So why would it fail the query?
  16. Thanks ober, I will be using a database.

    While were here on the subject tho, will I have to use this If for instance the customer name entered does not exist can it still put the details into the form but not enter it into the database so that the other fields can be filled in manually by the user, before using a submit to Insert it into the database?
  17. Cheers for the pointer.  I have heard of AJAX but didn't reaslise how it was needed.  Now I have to learn some JavaScript and XLM too, damn, was just learnin php first, but it'll all be good under the belt.
  18. Is it possible to have a selection box with values from a table.  But when the form starts it has an empty value, then the user can type into it and as it does it finds the record that matches the user input?

    If so what method must I use?
×
×
  • 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.