Dave wrote:
guys say if I include("anyfile.php") into a file. Is it possible for me to
access the calling page from anyfile.php.
Can I do something like this for instance::
if callingpage == "newauthor.php"
then mysql(INSERT into author.....)
else
mysql(INSERT into content...)
Thanks.
$_SERVER['PHP_SELF'] will tell you which file has been called, this will
include the path that has been given in the URL
eg
http://mydomain.net/some/path/myscript.php
$_SERVER['PHP_SELF'] -> /some/path/myscript.php
Another method would be using variables set in the page that calls your
"anyfile.php"
---in your myscript.php---
<?PHP
$IS_AUTH=FALSE;
include("anyfile.php");
....
--- eof ---
---in your newauthor.php---
<?PHP
$IS_AUTH=TURE;
include("anyfile.php");
....
--- eof ---
---in your anyfile.php---
<?PHP
/* if you have more than 2 options, then
* use a value insted of bool and use swtich()
*/
if ($IS_AUTH) {
$query="INSERT INTO author.....";
} else {
$query="INSERT INTO content...";
}
@mysql_query($query);
....
--- eof ---
Or you can do a function that you call from the main scripts
---in your anyfile.php---
<?PHP
function auto_insert($table,$values) {
/* $table is a string
* $values is a string with the values to insert)
*/
$query="INSERT INTO $table VALUES($values)";
@mysql_query($query);
}
....
--- eof ---
<?PHP
include("anyfile.php");
....
auto_insert("content",$values);
....
--- eof ---
---in your newauthor.php---
<?PHP
include("anyfile.php");
....
auto_insert("author",$values);
....
--- eof ---
So you have quite a lot of options, and it's all up to you how you want to do
things...
//Aho