|
Posted by Pedro Graca on 10/23/06 13:17
James54321 wrote:
> It seems there was a problem with having the functions so i put the
> code from them in the right places and it now works, but its really
> messy now.. so if anyone knows what is wrong with them please tell me
Your problem was that variables inside a function only belong to that
function unless declared global.
<?php
$a = 42;
$b = 24;
function print_number($number) {
global $b; // $b inside this function is the global $b
echo $number; // ok
echo $a; // not ok: $a here is internal to the function.
echo $b; // ok, $b was declared global
}
print_number(17);
?>
You were trying to reconnect to the database (why?) inside the functions
<?php
function submission_something($id) {
mysql_connect($user, $pass, $host); // here $user, $pass, and
// $host are internal
// variables
}
Either declare the variables global, pass them as parameters to the
function (better) or do not keep connecting throughtout the script (best).
<?php
// connect once!
// do your stuff, including calling submission_something()
// disconnect once!
function submission_something($id) {
$sql = "select from table where id=$id";
$resource = mysql_query($sql); // will use last connection
// ...
mysql_free_resource($resource);
}
?>
Happy Coding :)
--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Navigation:
[Reply to this message]
|