6 years later and I'm still learning more about PHP!

Oh great!! Thank you very much!!!!! a million times!!!

Solved! :D

( ! ) Parse error: syntax error, unexpected T_ELSE in C:\wamp\www\hacks4all.wapzan.com\registration\login.php on line 44

[CODE] <?php
// dBase file
include "dbConfig.php";

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

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

$sql = "Select COUNT(*) from `dbusers` where username = '$username' AND password = '$password'";

$result=mysql_query($sql);

//check that at least one row was returned

$rowCheck = mysql_result($result, 0);

if($rowCheck > 0) {

$_SESSION['username'] = $username;

header ("Location: index.php");

//we will redirect the user to another page where we will make sure they're logged in

} else {
//if nothing is returned by the query, unsuccessful login code goes here...

echo 'Incorrect login name or password. Please try again.<br>';

echo "$username - $password";

}
{
//If all went right the Web form appears and users can log in
echo "<form action=\"?op=login\" method=\"POST\">";
echo "Username: <input name=\"username\" size=\"15\"><br />";
echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
echo "<input type=\"submit\" value=\"Login\">";
echo "</form>";
}
?>[/CODE]

It looks like I can now login and logout, but there's one last thing.

Why do I get a notice?

( ! ) Notice: Undefined variable: username in C:\wamp\www\hacks4all.wapzan.com\registration\login.php on line 14

I can still login and log out.

Done

I now have:
[CODE] <?php
session_start();
// dBase file
include "dbConfig.php";

{
//If all went right the Web form appears and users can log in
echo "<form action=\"?op=login\" method=\"POST\">";
echo "Username: <input name=\"username\" size=\"15\"><br />";
echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
echo "<input type=\"submit\" value=\"Login\">";
echo "</form>";
}
?>[/CODE]

I don't know how to redirect the information to the actual logger..

Uhm....alright but I'm still having some problems
[url]http://fifarulez.dyndns.org/hacks4all.wapzan.com/registration/login.php[/url]

which are

( ! ) Notice: Undefined variable: username in C:\wamp\www\hacks4all.wapzan.com\registration\login.php on line 14
( ! ) Notice: Undefined variable: password in C:\wamp\www\hacks4all.wapzan.com\registration\login.php on line 14

My passwords aren't in md5 though.

Last thing!!!

For the login.php, it says that the information is wrong.

Is it the same lines I gotta change?

Wow.... it works perfectly.

Oh okay, thank you very much!

Where do I exactly insert the code?

Is there another way to set this?
Like post username, pass and email with one line? or something?

thanks

Or maybe it's just this that you wanted
[CODE]// Fields are clear, add user to database
// Setup query
$q = "INSERT INTO dbusers (username,password,email) "
."VALUES ('".$_POST["username"]."', "
."PASSWORD('".$_POST["password"]."'), "
."'".$_POST["email"]."')";
// Run query
$r = mysql_query($q);[/CODE]

Sorry, im really a newbie to this.

[CODE] <?php

// dbConfig.php is a file that contains your
// database connection information.
include ("dbConfig.php");

//Input vaildation and the dbase code
$op = isset($_GET['op']) ? $_GET['op'] : '';
if ($op == 'reg')
{
$bInputFlag = false;
foreach ( $_POST as $field )
{
if ($field == "")
{
$bInputFlag = false;
}
else
{
$bInputFlag = true;
}
}
// If we had problems with the input, exit with error
if ($bInputFlag == false)
{
die( "Problem with your registration info. "
."Please go back and try again.");
}

// Fields are clear, add user to database
// Setup query
$q = "INSERT INTO `dbusers` (`username`,`password`,`email`) "
."VALUES ('".$_POST["username"]."', "
."PASSWORD('".$_POST["password"]."'), "
."'".$_POST["email"]."')";
// Run query
$r = mysql_query($q);

// Make sure query inserted user successfully
if ( !mysql_insert_id() )
{
die("Error: User not added to database.");
}
else
{
// Redirect to thank you page.
Header("Location: register.php?op=thanks");
}
} // end if

//The thank you page
$op = isset($_GET['op']) ? $_GET['op'] : '';
if ($op == 'thanks')
{
echo "<h2> Thanks for registering!</h2> ";
}

//The web form for input ability
else
{
echo "<form action=\"?op=reg\" method=\"POST\"> \n";
echo "Username: <input name=\"username\" MAXLENGTH=\"16\"> <br /> \n";
echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"> <br /> \n";
echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"> <br /> \n";
echo "<input type=\"submit\"> \n";
echo "</form> \n";
}
// EOF
?>[/CODE]

Oh okay, some people set it to 255 I think but even with md5 on..

I cannot register if I have a password filled in..look
[url]http://fifarulez.dyndns.org/hacks4all.wapzan.com/registration/register.php[/url]

Try anything just to test.. and you'll see..

Thanks for the quick reply though

I tried changing:
[CODE]password CHAR(16),[/CODE]
to
[CODE]password VARCHAR(16),[/CODE]
but it still won't register with a password.. does this have something to do with md5?

fifarulez Light Poster

I can't seem to get my register page working with a password.

This is the query I executed:
[CODE]CREATE TABLE dbUsers (
id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(16) unique,
password CHAR(16),
email VARCHAR(25)
);[/CODE]
It only registers if there is no password filled..

Test it for yourself..
[url]http://fifarulez.dyndns.org/hacks4all.wapzan.com/registration/register.php[/url]

The only thing that comes to my head is that it could be...an sql error.

I need to find a query to execute on SQL that will give me
id auto increment and primary key..
username unique
password
email

thanks

Everything seems to work when I don't input a password...
it's
[CODE]password char(16)[/CODE]

Okay, I'll try.

Oh I see, and I don't really understand the question but..
This is the query I'm trying to execute on SQL
[CODE]CREATE TABLE dbUsers(
id int(10) Primary Key, AUTO_INCREMENT
username varchar(16) Unique
password char(16)
email varchar(25)[/CODE]
but it doesn't work....

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'username varchar(16) Unique
password char(16)
email varchar(25)' at line 3"

fifarulez Light Poster

I'm almost done making my registration system on my home server.

Thanks to everyone for your help.

The last thing I would like to know is why it says: Error: [U]User not added to database.[/U]

This is part of my register code:
[CODE] // Fields are clear, add user to database
// Setup query
$q = "INSERT INTO dbusers (username,password,email) "
."VALUES ('".$_POST["username"]."', "
."PASSWORD('".$_POST["password"]."'), "
."'".$_POST["email"]."')";
[/CODE]
My database is made and named like in dbconfig.php
[CODE] $db = "mysqladmin";[/CODE]

My table is dbusers but the columns/rows are made manually...

What could be the problem?

Solved.

Well, for mysql I do have a password, and the rest is localhost and root.
I left everything as it was, simply clicked next next next, done.

No..

Welcome to phpMyAdmin

Error
MySQL said:

1045 - Access denied for user 'root'@'localhost' (using password: NO)

phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.

dbConfig.php is placed with the other files but I can make it skip the problem by adding the information directly into register.php and forget the dbconfig.php

but the error after the registration still exists. I think it's WAMP.

It usually starts by itself, but I can do it manually by pressing "Start all services"
Which includes php and mysql. At the loading point it doesn't turn green, just yellow which is half the services on.

Maybe a conflicting port? I am able to access my db on another computer using my WAN ip and the port 3306.

fifarulez Light Poster

Hello, like before, I'm still trying to make a register page with login and logout.

Here's the link to my server (If I'm not allowed to share links please remind me.)
[url]http://fifarulez.dyndns.org/hacks4all.wapzan.com/registration/[/url]
After the registration it will give 2 warnings.

( ! ) Warning: mysql_query() [function.mysql-query]: Access denied for user ''@'localhost' (using password: NO) in C:\wamp\www\hacks4all.wapzan.com\registration\register.php on line 40

and

( ! ) Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\hacks4all.wapzan.com\registration\register.php on line 40

I tried to fix it by changing the code in:
[CODE] // dbConfig.php is a file that contains your
// database connection information. This
// tutorial assumes a connection is made from
// this existing file.
include ("dbConfig.php");[/CODE]

by

[CODE] // Replace the variable values below
// with your specific database information.
$host = "localhost";
$user = "root";
$pass = "CENSORED";
$db = "CENDORED";

// This part sets up the connection to the
// database (so you don't need to reopen the connection
// again on the same page).
$ms = mysql_pconnect($host, $user, $pass);
if ( !$ms )
{
echo "Error connecting to database.\n";
}

// Then you need to make sure the database you want
// is selected.
mysql_select_db($db);[/CODE]

When I do that the only thing I see is:
Error: User not added to database.

ps. I think that it's my WAMP server that isn't fully on since it's yellow, probably SQL is offline?

Thanks in advance! :)

fifarulez Light Poster

Hello and thanks for reading my thread.
I'm willing to start coding a little bit, specially php. This website has a lot of useful information that a rookie like me could use.

I have a homeserver that isn't very powerful or big for storage(120GB) but it can be used for testing. So if any of you need to test small projects that won't be such a hassle, I'd be very happy to share it with you for free, no catch.
It's at [snipped] please don't attack it or damage it, I'm sure you can destroy it easily but that's not the point here.

The community here seems very friendly and fast. Yesterday I posted one of my problems and today I wake up, BAM, already solved.. that's very nice.

Oh, almost forgot, my name is Emanuel and I'm 16 years old from Canada.

I hope this forum keeps getting larger and even better every day! :)

fifarulez Light Poster

Hello, I've always liked coding and lately I've learned a little but more of it.
Now I also understand sql and db a little more.

My problem is that my register.php file seems to give me a notice.

Notice: Undefined index: op in C:\wamp\www\hacks4all.wapzan.com\registration\register.php on line 11
and
Notice: Undefined index: op in C:\wamp\www\hacks4all.wapzan.com\registration\register.php on line 55

the code is the following:
[CODE] <?php

// dbConfig.php is a file that contains your
// database connection information. This
// tutorial assumes a connection is made from
// this existing file.
include ("dbConfig.php");

//Input vaildation and the dbase code
if ( $_GET["op"] == "reg" )
{
$bInputFlag = false;
foreach ( $_POST as $field )
{
if ($field == "")
{
$bInputFlag = false;
}
else
{
$bInputFlag = true;
}
}
// If we had problems with the input, exit with error
if ($bInputFlag == false)
{
die( "Problem with your registration info. "
."Please go back and try again.");
}

// Fields are clear, add user to database
// Setup query
$q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) "
."VALUES ('".$_POST["username"]."', "
."PASSWORD('".$_POST["password"]."'), "
."'".$_POST["email"]."')";
// Run query
$r = mysql_query($q);

// Make sure query inserted user successfully
if ( !mysql_insert_id() )
{
die("Error: User not added to database.");
}
else
{
// Redirect to thank you page.
Header("Location: register.php?op=thanks");
}
} // end if

//The thank you page
elseif ( $_GET["op"] == "thanks" )
{
echo "<h2> Thanks for registering!</h2> ";
}

//The web form for input ability
else
{ ...