scottybwoy Posted September 15, 2006 Share Posted September 15, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/20855-working-on-a-small-simple-script-not-working-right/ Share on other sites More sharing options...
HuggieBear Posted September 15, 2006 Share Posted September 15, 2006 I'm watching this thread for a solution, but unable to provide one I'm afraid :(Huggie Quote Link to comment https://forums.phpfreaks.com/topic/20855-working-on-a-small-simple-script-not-working-right/#findComment-92479 Share on other sites More sharing options...
sasa Posted September 17, 2006 Share Posted September 17, 2006 in[code]$this->connected == TRUE or die;[/code]script die becouse the variable $connected is not set up Quote Link to comment https://forums.phpfreaks.com/topic/20855-working-on-a-small-simple-script-not-working-right/#findComment-93580 Share on other sites More sharing options...
scottybwoy Posted September 19, 2006 Author Share Posted September 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20855-working-on-a-small-simple-script-not-working-right/#findComment-94507 Share on other sites More sharing options...
scottybwoy Posted September 19, 2006 Author Share Posted September 19, 2006 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 28Thank ppl Quote Link to comment https://forums.phpfreaks.com/topic/20855-working-on-a-small-simple-script-not-working-right/#findComment-94589 Share on other sites More sharing options...
scottybwoy Posted September 20, 2006 Author Share Posted September 20, 2006 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 35Can I not have = TRUE, or what is it saying. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/20855-working-on-a-small-simple-script-not-working-right/#findComment-95169 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.