![]() |
|
#1
|
|||
|
|||
variables in functions helpAiight i'm having a few probs assigning a value to a variable. In the main progam code I can assign the same variable different values. In this case i'm using a boolean variable called $haltemail to work with a sendmail script. It is false at the beginning of the code, and if any errors occur then its value is changed to true. This works all good except for when I use a to check for errors, and then another function to display error messages. Somewhere in my code the value isn't being assigned to the same variable. IE it stays false when I say: $haltemail = true;
There is obviously and issue with how I use this variable with the functions...but I though if I originally declared the variable not being in a function..it should be a global varable and all functions use that variable? Take a look at my example code, this is how i declare my $haltemail variable in my main program: PHP Code:
if error occured $haltemail should be set to true and email not sent but this is not happening...help!!! |
|||
|
#2
|
||||
|
||||
|
It looks like a very simple fix. Since $haltemail is not global, that function manipulates it privately. Nonetheless, I see that you are returning the value of $haltemail, but when you call the function, you aren't retrieving the returned value.
Therefore, the fix will be as follows... change this code: PHP Code:
To say this instead: PHP Code:
I hope this helps. |
|
#3
|
|||
|
|||
|
hmmm okay i guess i soughta understand that...
Lets say if i was to declare $haltemail = true in one function called print_error...would it the same concept? Like so: Instead of declaring the $haltemail variable here... PHP Code:
...I want to declare it in the print_error function. IE when ever there is an error. So would this work?: PHP Code:
Or is there not a way to make $haltemail a completely global variable where i don't have to use varaible passing between functions etc? |
|
#4
|
|||
|
|||
|
thanx alot jasonmichael big help i have finally solved my problems!!
Check out my code in action: fill out the form however you want...this email will not be sent cos the hidden $recipient field is set to user@hotmail.com which is not allowed recipient. www.spliffsa.com My sendmail script was being abused by spammers, now i have successfully secured it through using only allowed recipient email addy's. Check out the main contact page: www.spliffsa.com This contact page will eventually control all form data throughout the site... Peace! |
|
#5
|
|||
|
|||
|
Here's some of the working code to check email and recipient validility with a working $haltemail variable....
PHP Code:
|
|
#6
|
||||
|
||||
|
Looks pretty good! I'm glad it worked out.
|
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| passing variables out of an iframe by url | JUNK KED | MySQL / PHP Forum | 5 | 31-Jul-2007 10:33 |
| conflict between printf and stdarg.h va functions | mirizar | C Programming Language | 3 | 12-Jul-2004 09:11 |
| About variables in C | mantako | C Programming Language | 3 | 08-Jul-2004 05:11 |
| Understanding functions | tommy69 | C Programming Language | 15 | 15-Mar-2004 18:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The