/    Sign up×
Community /Pin to ProfileBookmark

Using a variable in a function ?

Hello all.

I have a function in which I change a variable but I can not ssem to use it later on 😮

Here is the little function and the script:

[code=php]function doIt($img)
{
if !($hh1 = (@file_get_contents($img))) {
$message2 = “This image is not good”;
return;
} // end if
} // end of function

$message1 = “none”;
$message2 = “none”;

doIt($image);
if($message2 != “none”){
$message1 = “The Picture file did not upload” ;
require_once (“disPicts.php”);
exit();
} // endif[/code]

The disPicts.php contains this:

[code=php]
if($message1 != “none”){
echo “<span style=’color:blue; font-weight:bold;’>$message1<br>$message2</span> “;
} // end if[/code]

So should I be able to see this message:

[QUOTE]

The Picture file did not upload
This image is not good”;

[/QUOTE]

or do I need to “pass” the variable $message2 out of the function ?

For some reason I am only getting:

[QUOTE]

The Picture file did not upload

[/QUOTE]

Thanks for your help ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bokehNov 11.2006 — You are setting the variable in local scope only (within the function). Either set is by reference or return it.[code=php]function GetResource($path)
{
return(@imageCreateFromString(@file_get_contents($path)));
}


if(!($resource = GetResource($path)))
{
$message1 = 'Picture file 1 did not successfully upload';
# what is this below ???
require_once ("a_picts_fm.php");
exit();
}[/code]
Copy linkTweet thisAlerts:
@sitehatcheryNov 11.2006 — [code=php]function doIt($img, $message=NULL)
{
if !($hh1 = (@file_get_contents($img))) {
$message = "Error: This image is not good";
return $message;
} // end if

} // end of function

$message=doIt($image);
if(!empty($message)){
echo $message
require_once ("disPicts.php");
exit();
} // endif
[/code]
Copy linkTweet thisAlerts:
@jeddikauthorNov 11.2006 — Thanks - that helped!
×

Success!

Help @jeddik spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...