Forum Moderators: coopster
The rest of the script (the query) is still executed
Although "echo" shows the corresponding warning
Nevertheless the query is executed
How can I be sure that if conditions are not met
then the query is not exec
Thank you
<?php
if (strlen($_POST['username'])<1 ¦¦
{
echo '<div align="center">Sorry, Go Back - Missing Fields -.</div>';
}
if (strlen($_POST['username'])<4 ¦¦
strlen($_POST['username'])>12 ¦¦
{
echo '<div align="center">Username and Password must be between 4 and 16 Characters.</div>';
}
?>
<?
if (strlen($_POST['username'])>3 ¦¦
etc....
{
$username=$_POST['username'];
$password=$_POST['password'];
$page=$_POST['page'];
$business_name=$_POST['business_name'];
$full_name=$_POST['full_name'];
$description=$_POST['description'];
$query = "INSERT INTO eco_dev (username, password, etc.................. #########
$result= mysql_query ($query);
}
else
{
echo "Sorry, you need to fix a few problems, please click your back browser";
}
?>
Those examples do not speak to me
it is still based on my typing
<<
if (strlen($_POST['username'])<1 ¦¦
{
echo '<div align="center">Sorry, Go Back - Missing Fields -.</div>';
}
>>
I need to understand where is the error?
and why is the rest of the script still executing
thanks
Let's break this down
if (strlen($_POST['username'])<1 ¦¦
Start with the if
syntax: if (expression)
You must have opening and closing parentheses around your expression. You open, but do not close. That gives:
if (strlen($_POST['username'])<1) ¦¦
Now the next problem is the
¦¦
This is the OR operator. You need another expression to follow it as in
if (expression ¦¦ expression)
Since you don't have two expressions, you cannot have an OR operator.
Two more things quickly.
First, in an if statement, an expression that evaluates to a value greater than zero or an empty string, is true. Zero or an empty string evaluates to false. So for the purposes of an expression evaluated in an if or a while, for example,
1 = "asdf" = true
0 = "" = false
If $_POST['username'] is set to "asdf" then strlen($_POST['username']) is equal to 4 which evaluates to true. So these are all equivalent (testing now for the positive case, not the negative as in your original code):
if (strlen($_POST['username']) > 0)
if (strlen($_POST['username']))
if ($_POST['username'])
Finally, you probably should test that $_POST['username'] is set. If it isn't you may get a warning depending on how your server has error reporting set (you probably won't, but it's not a bad practice). Thus your final statement becomes
if (isset($_POST['username']) && $_POST['username'])
Or, if you prefer
if (isset($_POST['username']) &&!empty($_POST['username']) )
To make it short I got it working;one glitch in 500+ lines but I know that was a brain dead one