•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,550 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,565 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 630 | Replies: 2
![]() |
•
•
Join Date: May 2006
Posts: 45
Reputation:
Rep Power: 3
Solved Threads: 0
Hello, I am sort of new to PHP programming. I am very familiar with C++, but i seem to be having some stupid little problems in PHP.
The code I am writing is to validate the information from a form and then email the information in the form to an email account I set up.
first problem: I have a portion of my page where the output is determined by whether or not the email is sent successfully, problem is, both the confirmation and the failure messages show up on the web browser. Somehow, both of my echo statements are making it to the web browser. What did I miss? (and this little bit of php is only a portion of the rest of the php, but this is the only part I have a problem with.)
(some HTML code here)
[php]if ($submit) { // If submit flag is 1, send mail
prepvars();
sendmail();
if ($success) { // If mail sent successfully, display confirmation
echo ("<h3 align=\"center\">Your Submit was successful. We will contact you back as soon as possible.
Thank you.</h3>");
} else { // If not successful, tell user
echo ("<h3 align=\"center\">Your Submit failed. Sorry for the inconvienience. Please Re-Submit, or try again
at a later time.</h3>");
} // End Submission Failure Warning
}[/php]
(more HTML here)
Second problem: Can someone explain the scope of variables a little better to me. My email is being sent to the email account fine, but any portions of the email that would contain variable are empty.
I have a form, then all variables are passed via POST, then in the php script they are processed and then mailed. A lot of the processing happens inside of functions, and then they are mailed by the mail() function. Why are all of my variables blank? Am I getting their scope messed up, such that I, Ideally, i want to get a local variable, but instead it grabs an empty global variable.
Final problem: is there any way to include large portions of HTML within PHP code, without having to escape every single set of quotes? Is there a program that will take code and escape all the quotes for you?
If anyone can help any of my problems, I would really appreciate it.
The code I am writing is to validate the information from a form and then email the information in the form to an email account I set up.
first problem: I have a portion of my page where the output is determined by whether or not the email is sent successfully, problem is, both the confirmation and the failure messages show up on the web browser. Somehow, both of my echo statements are making it to the web browser. What did I miss? (and this little bit of php is only a portion of the rest of the php, but this is the only part I have a problem with.)
(some HTML code here)
[php]if ($submit) { // If submit flag is 1, send mail
prepvars();
sendmail();
if ($success) { // If mail sent successfully, display confirmation
echo ("<h3 align=\"center\">Your Submit was successful. We will contact you back as soon as possible.
Thank you.</h3>");
} else { // If not successful, tell user
echo ("<h3 align=\"center\">Your Submit failed. Sorry for the inconvienience. Please Re-Submit, or try again
at a later time.</h3>");
} // End Submission Failure Warning
}[/php]
(more HTML here)
Second problem: Can someone explain the scope of variables a little better to me. My email is being sent to the email account fine, but any portions of the email that would contain variable are empty.
I have a form, then all variables are passed via POST, then in the php script they are processed and then mailed. A lot of the processing happens inside of functions, and then they are mailed by the mail() function. Why are all of my variables blank? Am I getting their scope messed up, such that I, Ideally, i want to get a local variable, but instead it grabs an empty global variable.
Final problem: is there any way to include large portions of HTML within PHP code, without having to escape every single set of quotes? Is there a program that will take code and escape all the quotes for you?
If anyone can help any of my problems, I would really appreciate it.
•
•
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation:
Rep Power: 5
Solved Threads: 20
What's the value of $success?
The syntax of echo does not include ( or ).
echo "This is an echo statement.";
You can have large amounts of HTML (or even small amounts) by turning off PHP processing. Use the ?> tag to do that.
The code above has not been tested, it's merely an example.
The syntax of echo does not include ( or ).
echo "This is an echo statement.";
You can have large amounts of HTML (or even small amounts) by turning off PHP processing. Use the ?> tag to do that.
if ( $file_not_found )
{
?> //Tell PHP not to process this further
<font size="+2" color="red'>
Not found, the file is.
</font>
<?php //Ok, start processing again
}The code above has not been tested, it's merely an example.
www.uncreativelabs.net
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
•
•
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation:
Rep Power: 5
Solved Threads: 20
Oh yeah, about variable scope:
PHP doesn't treat scope like other languages. If you have a global, you have to declare it global in the function it's global. (Kinda goes against everything you think makes sense, doesn't it?) You can pass variables in via function headings, and they're always in out mode.
PHP doesn't treat scope like other languages. If you have a global, you have to declare it global in the function it's global. (Kinda goes against everything you think makes sense, doesn't it?) You can pass variables in via function headings, and they're always in out mode.
www.uncreativelabs.net
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Retrieve email I sent to the wrong person (Web Browsers)
- Dual booting questions (Windows Vista)
- NetBSD questions (*nix Software)
- Questions on Cookies (Techies' Lounge)
- Some questions (PCI and Add-In Cards)
- Newbie questions about Linux servers and BSD (Getting Started and Choosing a Distro)
- Couple of CSS questions (HTML and CSS)
- Main Options / Style Questions (C++)
- connect to password protected access db (Visual Basic 4 / 5 / 6)
- 3d Program (Game Development)
Other Threads in the PHP Forum
- Previous Thread: Setting up a cookie and saving the result in mySQL database
- Next Thread: script which will automatic startup for virtual machines under Microsoft Virtual Serv


Linear Mode