In Register.php, it contains a form.
<html>
<body>
<form action="Insert.php" method="post">
Email: <input type="text" name="email" /><br/>
Username: <input type="text" name="username" /><br/>
<input type="submit" name="Send Registration" value="Send Registration"/>
</form>
</body>
</html>
In Insert.php, it contain codes that do some validations.
<?php
if(!filter_var($_POST[email], FILTER_VALIDATE_EMAIL))
{
exit("E-mail is not valid");
}
else
{
if(!strlen($_POST[username])>=6)
{
exit("Username should be at least 6 characters");
}
else
{
// Continue other validations
}
}
?>
When i enter an invalid email address a click on 'send registration', it will show the error message "E-mail is not valid". So, i tried to enter a valid email address and key in 5 or lesser characters in the username field and click on 'send registration'. But it doesn't show the error message.
May i know what is wrong with my codes?
Sorry i am a beginner in programming and php.
Thanks in advance!
Your logic is wrong:
if(!strlen($_POST[username])>=6)
Replace with: *also note the ' characters in the variable (The ! negator is replaced with the less than, double negative, this is easier to understand if you have to look through a lot of code, you may miss the "!"
if (strlen($_POST['username'])<6)
Hope this helps.
Also something you may want to consider: Get rid of "insert.php" and put the code from THAT into the same page as the form. You can do something like this:
Form: <form method="post" action="'.$self.'">
(put in the top of the page inside the PHP brackets)
$self = $_SERVER['PHP_SELF'];
$username = $_GET['username'];
$email = $_GET['email'];
It depends on how you want it set up, use either POST or GET, I can't tell you which to use.
From here, you can manipulate your variables and whatever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With