I'm working on a project with PHP and I made this file:
<?php
$err = false;
if (isset($_POST['submit'])){
$projectname = $_POST['project_name'];
if (strlen($projectname)>10){
$err = true;
echo "
<script type='text/javascript'>
alert('Your project name contains too many words');
</script>
";
}
$emailone = $_POST['mail_one'];
$emailtwo = $_POST['mail_two'];
$numstars = $_POST['num_stars'];
$numchars = $numstars + 2;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Welcome To Email Guesser</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<br />
<h1 style="text-align:center;color: #F90B6D; font-family: 'Open Sans', sans-serif; font-size: 34px; font-weight: 300; line-height: 40px; margin: 0 0 16px;">Email Guesser <small>v0.2</small></h1>
<h1 style="text-align:center;color: #F90B6D; font-family: 'Open Sans', sans-serif; font-size: 24px; font-weight: 300; line-height: 32px; margin: 0 0 14px;"><a href="http://www.emailguesser.pouyavagefi.com">www.emailguesser.pouyavagefi.com</a></h1>
<br />
<div class="inner contact">
<!-- Form Area -->
<div class="contact-form">
<!-- Form -->
<form id="contact-us" method="POST" action="action.php">
<!-- Left Inputs -->
<div class="col-xs-6 wow animated slideInLeft" data-wow-delay=".5s">
<!-- Name -->
<input type="text" name="project_name" id="name" required="required" class="form" placeholder="Name Of Project" />
<!-- Another Email Address -->
<input type="email" name="mail_one" id="mail" class="form" placeholder="Other Email Address You May Know #1" />
<!-- Another Email Address Two -->
<input type="email" name="mail_two" id="mail" class="form" placeholder="Other Email Address You May Know #2" />
<!-- Subject -->
<input type="number" name="num_stars" id="subject" required="required" class="form" placeholder="Number Of Stars" />
</div><!-- End Left Inputs -->
<!-- Right Inputs -->
<div class="col-xs-6 wow animated slideInRight" data-wow-delay=".5s">
<!-- Message -->
<textarea name="message" id="message" class="form textarea" placeholder="Message"></textarea>
</div><!-- End Right Inputs -->
<!-- Bottom Submit -->
<div class="relative fullwidth col-xs-12">
<button type="submit" id="submit" name="submit" class="form-btn semibold">Submit</button>
</div><!-- End Bottom Submit -->
<!-- Clear -->
<div class="clear"></div>
</form><p><i>make your project online on social medias with this hashtag: <strong>#hcktck</strong></i></p>
</div><!-- End Contact Form Area --></br>
</div>
<hr class="style-one">
<!-- Showing Outputs -->
<div class="container outptut">
<h3>Returning Results:</h3>
<?php
if($err=false){
echo "
<p class='bg-primary'> Victim's email address is $numchars characters long</p>
<p class='bg-success'> This text indicates success.</p>
<p class='bg-info'> This text represents some information.</p>
<p class='bg-warning'> This text represents a warning.</p>
<p class='bg-danger'> This text represents danger.</p>
";
}else{
echo "<h4 style='color:red;'>an error occured, try again or contact with our developers.</h4>";
}
?>
</div>
<center> Visit Developer's Website <a href="http://pouyavagefi.com" target="blank">Pouya Vagefi </a> </center>
</div>
</body>
</html>
This file is called action.php
and whenever I run it with correct information it shows me an error occured, try again or contact with our developers.
which I have set before. Basically as you can see I have called a boolean variable ($err) which take true if any kind of error appeared (for example a project name which has too many chars).
But the problem is this variable is set to true even when I submit the form with correct info. However I have called at the $err = false at the top the page.
So why this thing happens ? Note that no php errors appears at all.