Jump to content

Working on a small simple script not working right.


scottybwoy

Recommended Posts

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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