a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Hosting from $3.99 per month!

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions. dd

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

PHP "if" and "else" problems

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> General Web Development >> PHP "if" and "else" problems
Page: [1]
 
womble

 

Posts: 5721
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
PHP "if" and "else" problems - 9/16/2006 9:10:42   
Can anyone tell me what's wrong with this PHP please? I've got a form confirmation page set up supposedly to show a message if the visitor's email address isn't entered in an email format, or if the required fields are left empty, or to display the info submitted if all was present and correct.

The form's submitting okay if all is well, and the empty fields bit's working just fine - the error message for empty fields comes up, but if the email format's wrong the error message for that comes up, but with the text for the successful submission coming up under it as well.

I know just enough PHP to be dangerous :), and I'm probably missing something completely obvious, but I can't see what's missing here.

Can anyone enlighten me please?

<?php
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<p>Please enter a valid email address<p>";
$badinput = "<p>Your feedback was NOT submitted</p>\n";
echo $badinput;
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<p>Required fields have not been completed – please fill in all required fields.</p>\n";
echo "<p>Click the link below to return to the form</p>\n";
}
else {
echo "<h2>Thank you!</h2>\n";
echo "<p>Date: <?php echo $todayis ?></p>\n";
echo "<p> Thank You <?php echo $visitor ?> ( <?php echo $visitormail ?> ) for your comments. We've received your comments and we'll respond to you as soon as we can.</p>\n";
echo "<p>Your message:</p>\n";
echo "<p>Attention: <?php echo $attn ?></p>\n";
echo "<p>Message:<br />\n";
echo "echo $notes; ?></p>\n";
echo "<p>IP address logged: <?php echo $ip ?></p>\n";
}?>


_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)
BonRouge

 

Posts: 42
Joined: 3/3/2006
Status: offline

 
RE: PHP "if" and "else" problems - 9/16/2006 9:26:57   
I think you want your second if statement to be 'elseif'. The 'if' kind of starts the if/else statement again. As it is, it checks if the email address is valid. It sees it isn't and prints your warning. Then it goes through the if/else statement that comes next. If the required fields are OK, it shows the submission was OK (the else part).

I hope that helps.

(in reply to womble)
womble

 

Posts: 5721
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
RE: PHP "if" and "else" problems - 9/16/2006 10:59:45   
:)
Thanks BobRouge - didn't I say it'd be something simple? :)

That got it working just fine...the only problem was that I realised that though the correct error message was showing, the form was still submitting....um, slight problem there...so enter the PHP die statement (yep, I considered using exit, but it's just not nearly so dramatic :)) - only problem was then that by stopping the PHP script dead in it's tracks, it also stopped the rest of the page displaying (the code for the rest of the page follows the error messages code block...

...solution? Take out the code for the rest of the page and stick it in an include, and stick the include before the die statements.

:)

/is incredibly happy because I've been unsuccessfully hacking this script to pieces all day - script that was working perfectly well before I decided that the results weren't pretty enough :)

Does what I want it to now though. :) Thanks again BonRouge. :)

_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)

(in reply to BonRouge)
Page:   [1]
OutFront Discoveries

All Forums >> Web Development >> General Web Development >> PHP "if" and "else" problems
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts