I've been reading through about passing variables to functions and I can only find references to using globals but I heard that was a bad idea.
Here's an example script...
The project I'm working on, I'd like to make use of a lot of functions. Most will require the same variables but all variables are based on user input.PHP Code:function add_to_database()
{
$query = "INSERT INTO table (name,age) VALUES ('".$name."', '".$age."')";
mysql_query($query);
}
function send_mail()
{
//using the same varibales to send an email
}
if (isset($_POST['submit']))
{
$name = $_POST['name'];
$age = $_POST['age'];
add_to_database();
send_mail();
}
else
{
//the form bit
}
I did read about using the define constant function but my variables are not constant so I don't think it would be any good to me.
Any ideas?
Thanks in advance.
Smithster.



Reply With Quote




Bookmarks