?
Solved

PHP if..else option in an else section

Posted on 2011-09-26
5
Medium Priority
?
225 Views
Last Modified: 2012-05-12
Hi
I have the following code in a web page and I need to specify if the {$_POST['txtUsername']} is blank not to say "invalid email address"
how can i do this?
Cheers
Mat
<?php 

} 

} 
else { 


  echo "Invalid email address."; 
} 

?>

Open in new window

0
Comment
Question by:funkkube
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:neorush
ID: 36663382
I'm not sure where the rest of the code is....but it would be something like this:
else if($_POST['txtUsername']=='') {
    echo "Invalid email address.";
}
0
 

Author Comment

by:funkkube
ID: 36666746
Hi
Thanks for that..but,,
when the page first opens the message still comes up with INVALID EMAIL which is what i am trying to get rid of..
I just need it to come once the user has pressed LOGIN - which i need to change to SUBMIT which i have just done..
cheers
mat

<p>Please register your email to gain access to vocal stems.</p>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    <p><label for="txtUsername">Email Address:</label> 
    <br /><input type="text" title="Enter your Email Address" name="txtUsername" /></p> 

    <p><input type="submit" name="Submit" value="Login" /></p> 

</form> 

<p>
  <?php 

if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['txtUsername'])) { 
  { 

?> 
  
  Right Click on link to download the file</p>
<p> <a href="xxxxx">b vox 1</a></p>
<p>
  <a href="/xxxxxx">b vox 2</a></p>
<p>
  <a href="/xxxxxx">lead vox</a>

<?php
 $to = "XXXXXXXXXXXX";
 $subject = "REMIX COMPETITION - SOMEONE HAS DOWNLOADED THE STEMS!";
 $body = "Another entry in the REMIX Competition from - {$_POST['txtUsername']}";
 if (mail($to, $subject, $body)) {
   echo("<p></p>");
  } else {
   echo("<p>.</p>");
  }
?>

<?php

$myFile = "remixcomp/mercyremix.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "{$_POST['txtUsername']} \n";
fwrite($fh, $stringData);
fclose($fh);



?>
  <?php 

} 

} 
else if($_POST['txtUsername']=='') { 
    echo "Invalid email address."; 
}

?>

Open in new window

0
 
LVL 6

Accepted Solution

by:
neorush earned 2000 total points
ID: 36668542
This should work:
<p>Please register your email to gain access to vocal stems.</p>
<form name="form" method="post" action="<?=$_SERVER['PHP_SELF']?>"> 
    <p><label for="txtUsername">Email Address:</label> 
    <br /><input type="text" title="Enter your Email Address" name="txtUsername" /></p> 
    <p><input type="submit" name="Submit" value="Login" /></p> 

</form> 

<p>
<?php 

if(isset($_POST['txtUsername']) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['txtUsername'])) {

?> 
  Right Click on link to download the file</p>
<p> <a href="xxxxx">b vox 1</a></p>
<p>
  <a href="/xxxxxx">b vox 2</a></p>
<p>
  <a href="/xxxxxx">lead vox</a>

<?php
 $to = "XXXXXXXXXXXX";
 $subject = "REMIX COMPETITION - SOMEONE HAS DOWNLOADED THE STEMS!";
 $body = "Another entry in the REMIX Competition from - {$_POST['txtUsername']}";
 if(mail($to, $subject, $body)) echo("<p></p>");
 else echo("<p>.</p>");
?>

<?php

	$myFile = "remixcomp/mercyremix.txt";
	$fh = fopen($myFile, 'a') or die("can't open file");
	$stringData = "{$_POST['txtUsername']} \n";
	fwrite($fh, $stringData);
	fclose($fh);

} 
else if(isset($_POST['txtUsername'])) { 
    echo "Invalid email address."; 
}

?>

Open in new window

0
 

Author Comment

by:funkkube
ID: 36671124
Genius!
Worked like a charm!
Thanks very much! :-)
0
 

Author Closing Comment

by:funkkube
ID: 36673258
Genius!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question