Jump to content


Photo

MySQL User Registration Problem


  • Please log in to reply
32 replies to this topic

#21 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 17 December 2006 - 02:45 PM

then i dont get it, the username and password are correct, look here is what the host says to put:

Posted Image

#22 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 17 December 2006 - 02:50 PM

ok i took the <> out of the password and now i get this:

"Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/lethalgaming.awardspace.com/register.php on line 24
No database selected"


Here is line 24:

"$username_exist = mysql_num_rows($checkuser);"

#23 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 17 December 2006 - 03:01 PM

that means your query doesn't work, try this:

$checkuser = mysql_query("SELECT `username` FROM `users` WHERE `username` = '".$username."'") or die(mysql_error());

and post here what error is given so we can help you.

Matt

#24 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 17 December 2006 - 03:21 PM

it looks like that query is in the row above it, heres all of register.php:

<?PHP

session_start();
ob_start();

//Include the configurations
include('config.php');

//Define a few variables
$x = $_GET['x'];
$u = $_GET['u'];

$firstname = $_POST['firstname'];
$username = $_POST['username'];
$password = md5($_POST['password']);
$email = $_POST['email'];
$gamertag = $_POST['gamertag'];
$gender = $_POST['gender'];

// lets check to see if the username already exists

$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");

$username_exist = mysql_num_rows($checkuser);


if($username_exist > 0){
echo "I'm sorry but the username you specified has already been taken. Please pick another one.";
unset($username);
include 'register.html';
exit();
}

// lf no errors present with the username
// use a query to insert the data into the database.

$query = "INSERT INTO users (firstname, username, password, email, gamertag, gender)
VALUES('$firstname', '$username', '$password', '$email', '$gamertag', '$gender')";
mysql_query($query) or die(mysql_error());
mysql_close();

echo "You have successfully Registered";

// mail user their information

$yoursite = 'LeThaL Gaming';
$webmaster = 'Sal (LeThaL P1STONS)';
$youremail = '[email protected]';

$subject = "You have successfully registered at $Lethal Gaming";
$message = "Dear $name, you are now registered at our web site.
To login, simply go to our web page and enter in the following details in the login form:
Username: $username
Password: $password

Please print this information out and store it for future reference.

Thanks,
$Sal";

mail($email, $subject, $message, "From: $LeThaL Gaming <$[email protected]>\nX-Mailer:PHP/" . phpversion());

echo "Your information has been mailed to your email address.";

?>



#25 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 17 December 2006 - 03:23 PM

look trust me!

what happens when you use this:

$checkuser = mysql_query("SELECT `username` FROM `users` WHERE `username` = '".$username."'") or die(mysql_error());

Matt

#26 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 17 December 2006 - 03:27 PM

i put it in now it says:

"No Database Selected"

do i have to add some stuff to it like my username or sumthing?

Edited by pistonsfreak, 17 December 2006 - 03:28 PM.


#27 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 17 December 2006 - 03:31 PM

back in config change:

mysql_select_db($db['name']);

to:

mysql_select_db($db['name']) or die(mysql_error());

Matt

#28 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 17 December 2006 - 03:40 PM

thank you, it worked, now that I can register i tried to log in and it says:

"Parse error: parse error, unexpected T_STRING in /home/www/lethalgaming.awardspace.com/login.php on line 19"

Heres login.php:

"<?php

//Database Information
$db['host'] = "fdb1.awardspace.com";
$db['user'] = "lethalgaming_lg";
$db['pass'] = "<italia>";
$db['name'] = "lethalgaming_lg";


//Connect To The Database

mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']);

session_start();
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);

$query = “select * from users where username=’$username’ and password=’$password’”;

$result = mysql_query($query);

if (mysql_num_rows($result) != 1) {
$error = “Bad Login”;
include “login.html”;

?>"

Edited by pistonsfreak, 17 December 2006 - 03:43 PM.


#29 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 17 December 2006 - 03:43 PM

<?php

//Database Information
$db['host'] = "fdb1.awardspace.com";
$db['user'] = "lethalgaming_lg";
$db['pass'] = "<italia>";
$db['name'] = "lethalgaming_lg";


//Connect To The Database

mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']);

session_start();
$username = $_POST['username'];
$password = md5($_POST['password']);

$query = "select * from `users` where `username`= '$username' and `password` = '$password'";

$result = mysql_query($query);

if (mysql_num_rows($result) == 0) {
$error = "Bad Login";
include "login.html";

} else {
$_SESSION['username'] = "$username";
include "memberspage.php";
}

?>

Should work fine now.

Matt

#30 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 17 December 2006 - 03:46 PM

now it says:

"Parse error: parse error, unexpected $ in /home/www/lethalgaming.awardspace.com/login.php on line 27"

with this code:

<?php

//Database Information
$db['host']= "fdb1.awardspace.com";
$db['user'] = "lethalgaming_lg";
$db['pass'] = "<italia>";
$db['name'] = "lethalgaming_lg";


//Connect To The Database

mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']);

session_start();
$username = $_POST['username'];
$password = md5($_POST['password']);

$query = "select * from `users` where `username`= '$username' and `password` = '$password'";

$result = mysql_query($query);

if (mysql_num_rows($result) == 0) {
$error = "Bad Login";
include "login.html";

?>


Edited by pistonsfreak, 17 December 2006 - 03:48 PM.


#31 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 17 December 2006 - 03:52 PM

<?php

//Database Information
$db['host']= "fdb1.awardspace.com";
$db['user'] = "lethalgaming_lg";
$db['pass'] = "<italia>";
$db['name'] = "lethalgaming_lg";


//Connect To The Database

mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']);

session_start();
$username = $_POST['username'];
$password = md5($_POST['password']);

$query = "select * from `users` where `username`= '$username' and `password` = '$password'";

$result = mysql_query($query);

if (mysql_num_rows($result) == 0) {
$error = "Bad Login";
include "login.html";
}

?>

You missed a closing }

Matt

#32 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 17 December 2006 - 03:56 PM

thanks for all the help guys it worked, i may need help in the future though :). and i need one more small favor Matt, when i log in it goes to a blank screen, what do i have to add to the code and where do i add it so it redirects you to the home page of the site. the url will be http://lethalgaming.....com/home2.html.

thanks

it doest just have to be matt, just anyone that knows the code and where to put it

anyone

no one?

#33 Demonslay

Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 973 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 20 December 2006 - 09:05 AM

After having read this entire thing (and had quite a laugh) I believe you should really consider going back to PHP 101. You've been completely ignoring the code Matt has given you several times, and then brought up other problems that I would think would be quite obvious. :blush:

If you need a login screen, you'd do this. Though, if you are wanting to show a different homepage for logged in people, making a seperate .html file would not be wise, as someone can easily access the page anyways, and you'd make it more difficult on yourself to manage things.
You should invest some study into basic PHP, and read up on member systems. Using a class would be your best bet, as it is much more flexible. I would send you an example of mine, but my laptop crashed, and I can only pray to God the techs can get my most important files off without having to fully whipe the hard-drive. :blush:

But here is the code you are asking for pretty much for the moment.
<?php

//Database Information
$db['host']= "fdb1.awardspace.com";
$db['user'] = "lethalgaming_lg";
$db['pass'] = "<italia>"; // Be sure to change this to your REAL password
$db['name'] = "lethalgaming_lg";


//Connect To The Database

mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']) or die(mysql_error());

session_start();
$username = $_POST['username']; // You should really add some SQL injection prevention to this variable
$password = md5($_POST['password']); // And this one

$result = mysql_query("SELECT * FROM `users` WHERE `username`= '$username' AND `password` = '$password'") or die(mysql_error());

if(mysql_num_rows($result) == 0){
$error = 'Bad Login';
include 'login.html';
}
else include 'home2.html';
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users