[PHP] Two little questions

2001-01-14 Thread James, Yz

OK, this will be laughably easy for you guys.

I want to write a function (until now, I have been heavily repeating code,
but it's time to trim everything down.)

The function basically needs to check that username and password have been
entered, and then check them against mysql data.  All I am unsure of is the
format for the function...  is it like this:

function CUP (
if ((!$alias) || (!$password)) {
header("Location: login.php");
exit;
}
);

And reference it later with CUP(); ?  Don't worry about the MySQL side of
things, I just need to know how to lay out the function.  Oh and if I can
put anything I want in the function.

Also, if I wanted to perform a search of a column in a mysql table for
"places", would the Syntax be something like this:

$sql = " SELECT * FROM table_name
WHERE place = LIKE \"$searched_word\" ";

?

Thanks in Advance,

James.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Two little questions

2001-01-14 Thread mOrP

James,

 function CUP (
 if ((!$alias) || (!$password)) {
 header("Location: login.php");
 exit;
 }
 );


usually a function has the following structure:


function name ( arguments ) { code }


of course you can put any whitspace inside:

function name ( arguments )
{
code
}

which makes it easy to read.

You can put anything you want inside a function, but you must know, that you
cannot directly access a variable, that is defined outside the function.


$name = "mOrP";

function print_name()
{
echo $name;
}

print_name();

will not work.

Then you must 'get' the global variables (like $name):


$name = "mOrP";

function print_name()
{
global $name;
echo $name;
}

print_name();


But it's better to work with the function arguments:

$name = "mOrP"

function print_name($name_arg)
{
echo $name_arg;
}

print_name($name);


notice, that there is no ";" behind the { ... } and the ( ... ) block in the
definition of the function.

Hope it helps,

mOrP.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Two little questions

2001-01-14 Thread mOrP


 function check_alias_password()
 global $alias, $password;

better:

global $alias;
global $password;

 {
 if ((!$alias) || (!$password)) {
 header("Location: login.php");
 exit;
 }
 }

 check_alias_password();

 work? Or would the last example need to be globals (variables) instead of
 global?


Yes, this will work - with the correction I've made, 'cause I'm not sure, if
you can assign two variables to 'global'...

But you can see, that it is not good to use the 'global' keyword, because
you must know the name of the variable, you use.

Look:


$name_1 = "Jan";
$name_2 = "Fritz";

function print_name($name_arg)
{
echo $name_arg;
}

print_name($name_1);
print_name($name_2);


You see, how flexible it is...

CU
mOrP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]