Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-08-2012, 06:03 PM   PM User | #1
SarahBlue
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
SarahBlue is an unknown quantity at this point
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");?>
SarahBlue is offline   Reply With Quote
Old 11-08-2012, 06:07 PM   PM User | #2
bjarneo
New Coder

 
Join Date: May 2012
Posts: 50
Thanks: 6
Thanked 4 Times in 4 Posts
bjarneo is an unknown quantity at this point
<td><input type='text' name'username'></td>

Try name='username'
bjarneo is offline   Reply With Quote
Old 11-08-2012, 06:17 PM   PM User | #3
SarahBlue
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
SarahBlue is an unknown quantity at this point
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 06:32 PM..
SarahBlue is offline   Reply With Quote
Old 11-08-2012, 07:21 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
: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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
SarahBlue (11-09-2012)
Old 11-09-2012, 03:01 PM   PM User | #5
SarahBlue
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
SarahBlue is an unknown quantity at this point
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 -_-
SarahBlue is offline   Reply With Quote
Old 11-09-2012, 03:02 PM   PM User | #6
SarahBlue
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
SarahBlue is an unknown quantity at this point
P.S

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

Thanks!!
SarahBlue is offline   Reply With Quote
Old 11-09-2012, 03:41 PM   PM User | #7
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,495
Thanks: 44
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 11-09-2012, 03:53 PM   PM User | #8
SarahBlue
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
SarahBlue is an unknown quantity at this point
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 03:57 PM..
SarahBlue is offline   Reply With Quote
Old 11-09-2012, 04:07 PM   PM User | #9
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 11-09-2012, 04:15 PM   PM User | #10
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,495
Thanks: 44
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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");?>
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 11-09-2012, 11:53 PM   PM User | #11
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
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!
Custard7A is offline   Reply With Quote
Reply

Bookmarks

Tags
code, error, mysql, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:51 PM.


Advertisement
Log in to turn off these ads.