Jump to content


Photo

Working on a small simple script not working right.


  • Please log in to reply
5 replies to this topic

#1 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 15 September 2006 - 11:58 AM

Ok I've made a class and put some functions in itand it's not returning what I want have a quick read first :
<?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();

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

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 15 September 2006 - 03:59 PM

I'm watching this thread for a solution, but unable to provide one I'm afraid :(

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 17 September 2006 - 05:39 PM

in
$this->connected == TRUE or die;
script die becouse the variable $connected is not set up

#4 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 19 September 2006 - 08:43 AM

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.

#5 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 19 September 2006 - 12:49 PM

Right, now I've changed it around a bit and now it's not connecting to the database, here's the 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();

?>

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

#6 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 20 September 2006 - 09:26 AM

Right I have this code nearly working now, but it fails on this query :
<?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;
	}
?>
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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users