Jump to content

if (strlen($username) < 5) not working and more problems like this


Mythic Fr0st

Recommended Posts

Currently, my "Mailed" function, which when you sign up, checks if your username, is less than 5, if it is, it sets a boolean to false, and at the end I have if (Bool[1] && Bool[2] == true) and so on...

so it wont go through, IF... that doesn't check out properly...

However... the only 3 out of 6, that show up are

Username is too short
Password too short
Confirm Password too short

BUT, even if they're 5 characters or more, it still shows!
it should be

Username is too short
Password is too short
Confirm Password is too short
Passwords do not match
Emails do not match
Terms and Conditions box has not been ticked

if anyone can tell me why this is happening, I'll greatly appreciate it... Considering some how it just stopped working (was working before O_O, and i didnt change anything I dont think!)


CODE:



[code]<?php session_start(); ?>
<html>
<head>
<style type="text/css">
body
{
background-image:
url('SilverBG.jpg')
}
</style>
</head>
<DIV STYLE='Position: absolute; top: 0; left: 0;'>
<!--<img src="Mythic Aeons Banner.jpg" width="1024" height="112">-->
</div>
<body>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<?php
//<!--
$username = "";
$pw1 = "";
$pw = "";
$bool[1]=true;
$bool[2]=true;
$bool[3]=true; // the booleans
$bool[4]=true;
$bool[5]=true;
$bool[6]=true;
function noerror()
    {
    $var131='<div style=\'Position: absolute; top: 104; left: 0;\'>
    <a href="Home.php"><img src="Home Button.gif" style="border: 0px;"></a>
    </div>
    <div style=\'Position: absolute; top: 144; left: 0;\'>
    <img src="BlackButton.gif" width="130" height="35">
    </div>
    <div style=\'Position: absolute; top: 177; left: 0;\'>
    <a href="Story.php"><img src="Story Button.gif" style="border: 0px;"></a>
    </div>
    <div style=\'Position: absolute; top: 217; left: 0;\'>
    <img src="BlackButton.gif" width="130" height="35">
    </div>
    <div style=\'Position: absolute; top: 250; left: 0;\'>
    <a href="Signup.php"><img src="Signup Button.gif" style="border: 0px;"></a>
    </div>
    <div style=\'Position: absolute; top: 290; left: 0;\'>
    <img src="BlackButton.gif" width="130" height="35">
    </div>
    <div style=\'Position: absolute; top: 323; left: 0;\'>
    <a href=""><img src="Forum Button.gif" style="border: 0px;"></a>
    </div>
    <div style=\'Position: absolute; top: 363; left: 0;\'>
    <img src="BlackButton.gif" width="130" height="35">
    </div>
    <div style=\'Position: absolute; top: 397; left: 0;\'>
    <a href="contact us.php"><img src="contact us.gif" style="border: 0px;"></a>
    </div>
    <div style=\'Position: absolute; top: 437; left: 0;\'>
    <img src="BlackButton.gif" width="130" height="35">
    </div>
    <div style=\'Position: absolute; top: 470; left: 0;\'>
    <a href=""><img src="membership button.gif" width=\'130\' style="border: 0px;"></a>
    </div>';
    echo $var131;
    }
$st='</div> <div align=\'center\'>';
echo $st;


$username = (isset($_POST['username']));
$pw1 = (isset($_POST['password1']));
$pw2 = (isset($_POST['password2']));
$em1 = (isset($_POST['email1'])); // the emails, usernames, passwords, and if t&c (terms and conditions)
$em2 = (isset($_POST['email2']));// box was checked
$tc=(isset($_POST['t&c']));
if (strlen($username) < 5)
    {
    $bool[1]=false;
    echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your username must be no less then 5 characters long.<br /></i></font>';
    }


if (strlen($pw1) < 5)
    {
    $bool[2]=false;
    echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your password must be no less then 5 characters long.<br /></i></font>';
    }


if (strlen($pw2) < 5)
    {
    $bool[3]=false;
    echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your confirm password must be no less then 5 characters long.<br /></i></font>';
    }

if ($em1!==$em2)
    {
    echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your e-mail\'s do not match.<br /></i></font>';
    $bool[4]=false;
    }
if ($pw1 !== $pw2)
    {
    echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your passwords do not match.<br /></i></font>';
    $bool[5]=false;
    }

if ($tc == "on")
    {
    echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Please check the terms & conditions box.<br /></i></font>';
    $bool[6]=false;
    }
$i=0;
for ( $i = 1; $i < 7; $i++)
    {
    if (!$bool[$i])
        {
        $i=20;
        $var2="<div align='center'><input type='button' value='Return' onClick='history.go(-1)'></div>";
        echo $var2;
        }
    }

if ($bool[1] == true && $bool[2] == true && $bool[3] == true && $bool[4] == true && $bool[5] == true && $bool[6] == true)
    {
    $con=mysql_connect("localhost","mythicae_MythicA","rainmaker");
    if (!$con)
        {
        die("Poo ".mysql_error());
        }
    $username=(isset($_POST['username']));
    $password1=(isset($_POST['password1']));
    $email1=(isset($_POST['email1']));
    mysql_select_db("mythicae_chars", $con)or die("Mailed ".mysql_error());

    mysql_query("INSERT INTO `users` SET
    `username` = '$username',
    `userpass` = '$password1',
    `email` = '$email1'");


    $inv = array("Iron Dagger", "Ignite");
    $inv=serialize($inv);

    $tcn=$username;
    mysql_query("INSERT INTO chars SET
    `mlvl` = 1,
    `charname` = '$tcn',
    `strlvl` = 1,
    `strdmg` = 0,
    `strxp` = 0,
    `strdiv` = 1,
    `dexlvl` = 1,
    `dexcth` = 0,
    `dexxp` = 0,
    `dexdiv` = 1,
    `currlife` = 20,
    `maxlife` = 20,
    `deflvl` = 1,
    `defxp` = 0,
    `defda` = 0,
    `defdiv` = 1,
    `intlvl` = 1,
    `intxp` = 0,
    `intdiv` = 1,
    `foclvl` = 1,
    `focxp` = 0,
    `focdiv` = 1,
    `mag` = 10,
    `weapon` = 'Iron Dagger',
    `spell` = 'Ignite',
    `gold` = 0,
    `bankedgold` = 10,
    `phd` = 0,
    `sa` = 1,
    `tstr` = 1,
    `tdex` = 0,
    `tdef` = 0,
    `tint` = 0,
    `tfoc` = 0,
    `currmonster` = 0,
    `magmax` = 10,
    `helm` = 'None',
    `bp` = 'None',
    `lp` = 'None',
    `shield` = 'None',
    `boots` = 'None',
    `amulet` = 'None',
    `ring` = 'None',
    `misc` = 'None',
    `wdmg` = 0,
    `vert` = 0,
    `horz` = 0,
    `currtown` = 'Open Plains',
    `inv` = '$inv'
    `equipment` = 0,
    `wisq` = 0,
    `belt` = 'None',
    `currlifemon` = 0,
    `currmaxlifemon` = 0,
    `dse` = 0,
    `lastfight` 0");





    $msg='<font color="darkred" size="4">Welcome to Mythic Aeons</font>';
    $subject='Activation Code';
    $from='[email protected]';
    $headers='From: '.$from;
    mail($email1,$subject,$msg,$headers);
    mysql_close($con);
    }
//-->

/*noerror();
echo "<font color='blue' size='4'>Welcome to Mythic Aeons <br /></b><i>Please go to your e-mail and follow the instructions on the e-mail to activate your account</i></font>";
$var47="<div align='center'><input type='button' value='Continue to login' onClick=\"location='Home.php'\"></div>";
echo $var47;*/
?>
</div>
</div>
</body>
</html>[/code]

Thanks
[quote author=play_ link=topic=121906.msg502082#msg502082 date=1168504758]

$username = (isset($_POST['username']));  ----> this will either give you 0 or 1. so it'll always be less than 5
[/quote]


That goes for all these:

$pw1 = (isset($_POST['password1']));
$pw2 = (isset($_POST['password2']));
$em1 = (isset($_POST['email1']));
$em2 = (isset($_POST['email2']));
hmm

But if I do

$username = $_POST['username'] I get the error

"Undefined index 'username'"

and, if I also had the problem doing it like this

if (isset($_POST['username']))
    {
    $username=$_POST['username'];
    }

still was always less than 5, but thanks I see why thats happen, any idea's how to fix it
Are you looking at this page with out posting? This includes when you did have the [quote]$username = $_POST['username'] I get the error

"Undefined index 'username'"[/quote] Notice... Also I'm pretty sure "Undefined index '*'" are notices not errors and will not change how your script is run. Try changing your php.ini. The normal, best way to have the set up is

[quote]error_reporting = E_ALL & ~E_NOTICE[/quote]

E_NOTICE is so annoying, it displays notices for everything.

I would recommend that you do have notices logged though. In case there is a time that you need to know something like this. :)
This code you have in your last post is correct:

[code=php:0]if (isset($_POST['username']))
    {
    $username=$_POST['username'];
    }[/code]


Then strlen($username) will only be less than 5 if the username really is less than 5 characters long.
Well... sorry to double post
[code]
if (isset($_POST['username']))
    {
    $username = $_POST['username'];
    if (strlen($username) < 5)
        {
        $bool[1]=false;
        echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your username must be no less then 5 characters long.<br /></i></font>';
        }
    }[/code]

is the code I used on username, and it just stopped appearing all together...

also

check out the problem at www.mythicaeons.com

go to signup, and then click the "SIGNUP" button on the page, you'll see
Mythic, this isn't  hard script to write, and it seems like you are coding an online-based word game.
If you're having trouble with the sign up form, you'll surely have trouble coding your game.
Perhaps you should buy a php book and read it from first to last page. even if the material isn't related to what you are doing....it will give you a huge jumpstart
[code=php:0]
<?PHP
$username = (isset($_POST['username'])) ? $_POST['username'] : '';
$pw1 = (isset($_POST['password1'])) ? $_POST['password1'] : '';
$pw2 = (isset($_POST['password2'])) ? $_POST['password2'] : '';
$em1 = (isset($_POST['email1'])) ? $_POST['email1'] : '';
$em2 = (isset($_POST['email2'])) ? $_POST['email2'] : '';
?>
[/code]

Is equivalent to writing:

[code=php:0]
<?PHP
if(isset($_POST['username'])) {
  $username = $_POST['username'];
}
else {
  $username = '';
}
?>
[/code]

I hope that helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.