View Full Version : If statment not working

09-23-2005, 08:44 PM
When I enter the username 700lbGorilla if goes to the "6-20 character statement" statement. Not understanding why, becase I've tested the preg_match statement before and it worked. Now that I have it in a different if statement it isn't working.

if(preg_match('/^[a-zA-Z0-9]\w*[a-zA-Z0-9]$/', $_POST['uname']))
if(strlen($_POST['uname'] > 5) && strlen($_POST['uname'] < 21)) {
$u = $_POST['uname'];
} else {
$u = FALSE;
echo '<p><font color="red">Username needs to be 6-20 characters.</font></p>';
} else {
$u = FALSE;
echo '<p><font color="red">Username is not in valid format.</font></p>';

09-23-2005, 09:06 PM
you seem to be missing a few brackets there... not sure it should even parse but...

if(strlen($_POST['uname'] > 5) && strlen($_POST['uname'] < 21)) { should be

if((strlen($_POST['uname']) > 5) && (strlen($_POST['uname']) < 21)) {

09-23-2005, 09:14 PM
Oh... thank you, didn't know I needed those ones. Another quick question has nothing to do with this topic. If you insert something into a DB that doesn't have a value, is it like inserting nothing?

09-23-2005, 09:33 PM
that depends how you insert it, if you insert

as $emptyvariable then I think it would count as NULL whereas '$emptyvariable' would be a zero length string I believe.

09-24-2005, 02:01 AM
It depends as well on your database setup. If your table is set up, and the column has "NOT NULL" set, the empty value (whether it be NULL or an empty string ""), will be inserted into the database as an empty string. If the column is set to NULL, then it will depend on your query.

A query to insert a NULL value:

INSERT INTO table VALUES ( 'value 1', NULL )

So if you are inserting an empty string with quotes around it, I think it will still count as as being a value and just insert the empty string (even the column is a NULL column)

By the way, if you are wondering, NULL columns have a use when it comes to counting. So say the field "value" in my table has some null entries, if I run

SELECT COUNT(value) FROM table

It will only return a count of the non-null entries, null entries are ignored in this case.