$_Post and function()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

$_Post and function()

Post 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).
User avatar
Alex-V
Forum Newbie
Posts: 17
Joined: Mon Jul 19, 2010 3:53 pm

Re: $_Post and function()

Post 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>
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

Re: $_Post and function()

Post 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.
Post Reply