...

View Full Version : Help Me Guys Please!!!



SarahBlue
11-08-2012, 06:03 PM
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");?>

bjarneo
11-08-2012, 06:07 PM
<td><input type='text' name'username'></td>

Try name='username'

SarahBlue
11-08-2012, 06:17 PM
<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!! )

Fou-Lu
11-08-2012, 07:21 PM
: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:


$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.

SarahBlue
11-09-2012, 03:01 PM
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
11-09-2012, 03:02 PM
P.S

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

Thanks!!

tangoforce
11-09-2012, 03:41 PM
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.

SarahBlue
11-09-2012, 03:53 PM
<?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");?>

Fou-Lu
11-09-2012, 04:07 PM
Wait a minute. Do you actually have those
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.

tangoforce
11-09-2012, 04:15 PM
Sarah, this is what I meant:


<?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");?>

Custard7A
11-09-2012, 11:53 PM
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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum