Page 1 of 1

$_Post and function()

Posted: Tue Jul 20, 2010 9:12 am
by IGGt
Is it possible to use $_POST to pass information into a function?

e.g. on page 1 I have a form which passes the value 'DBSchema' when the box is ticked.
On page 2 I then pick that up using

Code: Select all

if (isset($_POST['DBSchema'])) {
		$db = $_POST['DBSchema'];
		} else {
		$db = "Database Not Set"; }
This all works fine on various pages I have designed. However I now want to incorporate it into a function, e.g:

Code: Select all

function fQuery() {

if (isset($_POST['DBSchema'])) {
$db = $_POST['DBSchema'];
} else {
$db = "Database Not Set"; }
}

<Body>
<p><?php fquery() ?></p>
</body>

so I was wondering if it was possible (as so far it doesn't seem to work).

Re: $_Post and function()

Posted: Tue Jul 20, 2010 10:00 am
by Alex-V

Code: Select all

<?php
function fQuery() 
{
    $db = (isset($_POST['DBSchema']))? $_POST['DBSchema']: "Database Not Set";
    echo $db;
}
?>

<Body>
<p><?php fquery() ?></p>
</body>

Re: $_Post and function()

Posted: Tue Jul 20, 2010 10:25 am
by IGGt
cheers for that, that seems a bit neater than what I had.

I think the problem I had was that I was setting the $db in side the function, but then trying to call it separately.