MySQL User Registration Problem
#21
Posted 17 December 2006 - 02:45 PM
#22
Posted 17 December 2006 - 02:50 PM
"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
Posted 17 December 2006 - 03:01 PM
$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
Posted 17 December 2006 - 03:21 PM
<?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
Posted 17 December 2006 - 03:23 PM
what happens when you use this:
$checkuser = mysql_query("SELECT `username` FROM `users` WHERE `username` = '".$username."'") or die(mysql_error());
Matt
#26
Posted 17 December 2006 - 03:27 PM
"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
Posted 17 December 2006 - 03:31 PM
mysql_select_db($db['name']);
to:
mysql_select_db($db['name']) or die(mysql_error());
Matt
#28
Posted 17 December 2006 - 03:40 PM
"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
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
Posted 17 December 2006 - 03:46 PM
"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
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
Posted 17 December 2006 - 03:56 PM
thanks
it doest just have to be matt, just anyone that knows the code and where to put it
anyone
no one?
#33
Posted 20 December 2006 - 09:05 AM
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.
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