Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up Help Me Guys Please!!!

    Heyyyyy guys im trying to teach myself alongside this video im watching ive been following literally word for word got stuck a few times along way but managed to work out the problems myself,but this time im having no luck ive been stuck on this one for hours and hours any help hugely appreciated!!!

    So heres what ive got in code this is the activation.php page -
    previous to this one, was the register.php page which successfully sent out the activation link to my email.
    But when i fill in activation code/username and password it says the same freakin thing everytime
    "You did not fill in the entire form" ive spell checked it myself and by using dw's spell checker and everythings spelt correct :s?

    <?php $title = " Sarah - Activate Your Account"; ?>
    <?php require("styles/top.php"); ?>
    <div id='full'>
    <?php

    $getcode = $_GET['code'];

    $form = "<form action='activate.php' method='post'>

    <table>

    <tr>
    <td>Activate Code:</td>
    <td><input type='text' name='code' value='$getcode' size='30'></td>
    </tr>
    <tr>
    <td>Username:</td>
    <td><input type='text' name'username'></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input type='password' name='password'></td>
    </tr>
    <tr>
    <td></td>
    <td><input type='submit' name='submitbtn' value='activate'></td>
    </tr>
    </table>
    </form>";

    if ($_POST['submitbtn']){
    $code = strip_tags($_POST['code']);
    $username = strip_tags($_POST['username']);
    $password = strip_tags($_POST['password']);

    if ($code && $username && $password){
    if (strlen($code) == 25){
    $pass = md5(md5($password));
    require("scripts/connect.php");
    $query = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$pass'");
    $numrows = mysql_num_rows($query);
    if ($numrows == 1) {

    $row = mysql_fetch_assoc($query);
    $dbcode = $row['code'];

    if ($code == $dbcode){

    mysql_query("UPDATE users SET active='1' WHERE username='$username'");

    echo "Your account has beeen activated u may now login.<a href='login.php'>Click here to log in</a>";

    }
    else
    echo "Your activation code incorrect $form";


    }
    else
    echo "Your username and password are invalid $form";

    }
    else
    echo "You have not supplied a valid code $form";


    }
    else
    echo "You did not fill in the whole form $form";


    }
    else
    echo "$form";


    ?>
    </div>
    <?php require("styles/bottom.php");?>

  • #2
    New Coder
    Join Date
    May 2012
    Posts
    50
    Thanks
    6
    Thanked 4 Times in 4 Posts
    <td><input type='text' name'username'></td>

    Try name='username'

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy

    Quote Originally Posted by bjarneo View Post
    <td><input type='text' name'username'></td>

    Try name='username'

    Okay great!! im now getting a different error which is good which means that im not stuck on the same thing ive been for hours, its now saying your username and password are invalid :s I DONT UNDERSTAND why its saying it ive checked it over 4 times now changed so many things and all ending with the same result - FAILURE

    p.s (cant believe i didnt notice the first error, ive been looking to hard!! )
    Last edited by SarahBlue; 11-08-2012 at 07:32 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    :squints:
    You need to select better title for threads :P

    That said, this will always trigger a notice on the first time you load the page without a post: if ($_POST['submitbtn']){. Replace that with if (isset($_POST['code'], $_POST['username'], $_POST['password'])) {.
    This one may throw an error for the same reason: $getcode = $_GET['code'];. There is no verification that $_GET['code'] exists, but there is also no indication of what it should do if it doesn't exist. So that I'll just give a default value of nothing: $getcode = isset($_GET['code']) ? $_GET['code'] : '';.

    So guaranteed errors are the $_POST['submitbtn'] on the first load, and $_GET['code'] on posted loads with this current form. Fixes above will fix that.

    Change this: $query = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$pass'");
    To this:
    PHP Code:
     $sQry "SELECT * FROM users WHERE username='$username' AND password='$pass'";
     
    printf('Running: "%s"' PHP_EOL$sQry);
     
    $query mysql_query($sQry) or die('SQL error: ' mysql_error()); 
    Take that printed query and run that against a SQL client. Assuming you have a table users with properties username and password, then the query should be successful even if it returns no records. That would be caused by no matches, and assuming that the username is correct than that would be either the password hashing algorithm doesn't match what you have here, or that the field length of password isn't sufficient. MD5 (you shouldn't use this btw, even with multiple levels; use a stronger hash such as sha256) will return a 32 hex string, so you should have a db property of char(32) for it. If its less, its been truncated so you cannot make use of the existing records.

  • Users who have thanked Fou-Lu for this post:

    SarahBlue (11-09-2012)

  • #5
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy

    misleading title? maybe. . . . it got your attention though

    it still didnt work after all of the changes there, im way over my head im a smart girl but this is bit full on, you sound like you know what your talking about what advice can you give me on the best way of learning code??
    Because ive been following a community site tutorial but it goes in so deep and theres no way by the end of the 40th lesson im going to remember all of the lines and what they do as he doesnt explain he just types -_-

  • #6
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    P.S

    Although the last comments coding didnt work i am going to thank you for your effort

    Thanks!!

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,479
    Thanks
    63
    Thanked 538 Times in 525 Posts
    Quote Originally Posted by SarahBlue View Post
    Although the last comments coding didnt work i am going to thank you for your effort
    So post your new revised code (in [php] tags) and let us have a fresh look at what you currently have.

    Also any new error messages.
    I can't really think of anything to write here now...

  • #8
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Confused :s

    <?php $title = "BaisxNick - Activate Your Account"; ?>
    <?php require("styles/top.php"); ?>
    <div id='full'>
    <?php

    PHP Code:
    $getcode = isset($_GET['code']) ? $_GET['code'] : ''
    $form = "<form action='activate.php' method='post'>

    <table>

    <tr>
    <td>Activate Code:</td>
    <td><input type='text' name='code' value='$getcode' size='30'></td>
    </tr>
    <tr>
    <td>Username:</td>
    <td><input type='text' name='username'></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input type='password' name='password'></td>
    </tr>
    <tr>
    <td></td>
    <td><input type='submit' name='submitbtn' value='activate'></td>
    </tr>
    </table>
    </form>";

    PHP Code:
    if (isset($_POST['code'], $_POST['username'], $_POST['password'])) { 
    $code = strip_tags($_POST['code']);
    $username = strip_tags($_POST['username']);
    $password = strip_tags($_POST['password']);

    if ($code && $username && $password){
    if (strlen($code) == 25){
    $pass = md5(md5($password));
    require("scripts/connect.php");
    PHP Code:
    $sQry "SELECT * FROM users WHERE username='$username' AND password='$pass'";
     
    printf('Running: "%s"' PHP_EOL$sQry);
     
    $query mysql_query($sQry) or die('SQL error: ' mysql_error()); 
    $numrows = mysql_num_rows($query);
    if ($numrows == 1) {

    $row = mysql_fetch_assoc($query);
    $dbcode = $row['code'];

    if ($code == $dbcode){

    mysql_query("UPDATE users SET active='1' WHERE username='$username'");

    echo "Your account has beeen activated u may now login.<a href='login.php'>Click here to log in</a>";

    }
    else
    echo "Your activation code incorrect $form";


    }
    else
    echo "Your username and password are invalid $form";

    }
    else
    echo "You have not supplied a valid code $form";


    }
    else
    echo "You did not fill in the whole form $form";


    }
    else
    echo "$form";


    ?>
    </div>
    <?php require("styles/bottom.php");?>
    Last edited by SarahBlue; 11-09-2012 at 04:57 PM.

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Wait a minute. Do you actually have those [php][/php] tags in there? You need to remove those as that will throw a parse error. That's used for the forums to markup.
    That would be what you wrap your entire code in since it preserves the formatting.

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,479
    Thanks
    63
    Thanked 538 Times in 525 Posts
    Sarah, this is what I meant:

    PHP Code:
    <?php $title "BaisxNick - Activate Your Account"?>
    <?php 
    require("styles/top.php"); ?>
        <div id='full'>
        <?php
        
        $getcode 
    = isset($_GET['code']) ? $_GET['code'] : '';
        
        
    $form "<form action='activate.php' method='post'>

        <table>
        
        <tr>
            <td>Activate Code:</td>
            <td><input type='text' name='code' value='$getcode' size='30'></td>
        </tr>
        <tr>
            <td>Username:</td>
            <td><input type='text' name='username'></td>
        </tr>
        <tr>
            <td>Password:</td>
            <td><input type='password' name='password'></td>
        </tr>
        <tr>
            <td></td>
            <td><input type='submit' name='submitbtn' value='activate'></td>
        </tr>
        </table>
        </form>"
    ;
        
        if (isset(
    $_POST['code'], $_POST['username'], $_POST['password'])) {
            
    $code strip_tags($_POST['code']);
            
    $username strip_tags($_POST['username']);
            
    $password strip_tags($_POST['password']);
            
            if (
    $code && $username && $password){
                if  (
    strlen($code) == 25){
                    
    $pass md5(md5($password));
                    require(
    "scripts/connect.php");
                    
    $sQry "SELECT * FROM users WHERE username='$username' AND password='$pass'";
     
    printf('Running: "%s"' PHP_EOL$sQry);
     
    $query mysql_query($sQry) or die('SQL error: ' mysql_error()); 
                    
    $numrows mysql_num_rows($query);
                    if (
    $numrows == 1) {
                        
                        
    $row mysql_fetch_assoc($query);
                        
    $dbcode $row['code'];
                        
                        if (
    $code == $dbcode){
                            
                            
    mysql_query("UPDATE users SET active='1' WHERE username='$username'");
                            
                            echo 
    "Your account has beeen activated u may now login.<a href='login.php'>Click here to log in</a>";
                                
                        }
                        else
                            echo 
    "Your activation code incorrect $form";
                    
                        
                    }
                    else
                        echo 
    "Your username and password are invalid $form";
                    
                }
                else
                    echo 
    "You have not supplied a valid code $form";
                
        
            }
            else
                echo 
    "You did not fill in the whole form $form";
        
        
        }
        else
            echo 
    "$form";

            
        
    ?>
        </div>
      <?php require("styles/bottom.php");?>
    I can't really think of anything to write here now...

  • #11
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    Trying to learn alongside a video would be pretty hard, you couldn't go over it at your own pace! If you're serious about learning a programming language like PHP the first thing you should tackle is the concepts. Once you have a grasp of the syntax you will begin to read PHP like normal English, and it makes everything 100 times easier to learn.

    You wouldn't learn a foreign language by memorizing words someone says, you would need to understand the structure. It's the same with a programming language like PHP!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •