Jump to content

Help with a register / login form


Cochise

Recommended Posts

Im creating a game which will require users to register & login. But ive come to a halt on the register and login pages.

 

The problem with the register form is that it wont add tables into my database

 

The problem with the login form is that it wont accept my test account (i went into the database and manually entered the details)

 

Here is my register script:

<?php
session_start();
include_once"includes/db_connect.php";
if (isset($_SESSION['username'])){
header("Location: index.php");
exit();
}

$from_user=strip_tags($_POST['ref']);
if ($_POST['Submit']){

$reg_username = $_POST['reg_username'];

$email = $_POST['email'];
$email1 = $_POST['email1'];
$location=strip_tags($_POST['location']);
$reg_username=trim($reg_username);

$today = gmdate('Y-m-d h:i:s');


$reg_username = stripslashes($reg_username);
$email = stripslashes($email);
$quote = stripslashes($quote);
$reg_username = strip_tags($reg_username);
$email = strip_tags($email);




if((!$reg_username) || (!$email) || (!$location)){
$message="Fill in all fields";
}else{
if ($email != $email1){
$message="Emails do not match";
}elseif ($email == $email1){

if (ereg('[^A-Za-z0-9]', $reg_username)) {  $message="Your username can only contain letters and numbers.";
}elseif (!ereg('[^A-Za-z0-9]', $reg_username)) {


if (strlen($reg_username) <= 3 || strlen($reg_username) >= 20){
$message= "Username must be over 3 and under 20";
}elseif (strlen($reg_username) > 3 || strlen($reg_username) < 20){


$sql_email_check = mysql_query("SELECT email FROM users
            WHERE email='$email' AND status='Alive'");
$sql_username_check = mysql_query("SELECT username FROM users
            WHERE username='$reg_username'");

$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

if(($email_check > 0) || ($username_check > 0)){
    echo "Im sorry but there has been an error please read on..<br />";
    if($email_check > 0){
        $message= "Your email address has already been used!";
        unset($email);
    }
    if($username_check > 0){
        $message="Your desired username is already in use!";
        unset($reg_username);
    }


}else{


if ($location == 'England'){
$uk[0] = rand(51,104);
$uk[1] = rand(90,412);
$uk[2] = rand(68,296);
$uk[3] = rand(23,47);
$uk[4] = rand(2705,3312);
$implodething = implode("-", $uk);
////japan////
$city="Cambridgeshire";
}elseif ($location == 'Japan'){
$japan[0] = rand(149,259);
$japan[1] = rand(113,582);
$japan[2] = rand(12,74);
$japan[3] = rand(82,150);
$japan[4] = rand(1700,2832);
///France///
$city="Chiba";
$implodething = implode("-", $japan);
}elseif ($location == 'France'){
$France[0] = rand(31,301);
$France[1] = rand(80,397);
$France[2] = rand(23,118);
$France[3] = rand(90,123);
$France[4] = rand(316,812);
///usa////
$city="Bogota";
$implodething = implode("-", $France);
}elseif ($location == 'Usa'){
$usa[0] = rand(51,104);
$usa[1] = rand(90,412);
$usa[2] = rand(60,192);
$usa[3] = rand(98,116);
$usa[4] = rand(472,1003);
$city="Bogota";
///China////
$implodething = implode("-", $usa);
$city="New York";
}elseif ($location == 'China'){
$China[0] = rand(78,112);
$China[1] = rand(170,194);
$China[2] = rand(118,132);
$China[3] = rand(110,506);
$China[4] = rand(1500,1703);

}



$ip = $_SERVER['REMOTE_ADDR'];

$randomPass = substr(md5(microtime()), 0, ;
echo "Accont created, your password is: $randomPass";


mysql_query("INSERT INTO `user_info` ( `id` , `username` , `password` , `email` , `money` , `bullets` , `points` , `health` , `rank` , `rankpoints` , `weapon` , `armour` , `plane` , `location` , `ip` , `userlevel` )
VALUES (
'', '$reg_username' , '$randomPass` , `$email` , `10000` , `0` , `0` , `100` , `Civillian` , `0` , `None` , `None` , `None` , `$location` , `$ip` , `1` )");
   } }}}}}

?>

 

Here is my login check code:

 

<?
session_start();
header("Cache-control: private");
include 'includes/db_connect.php';



if (!$_SESSION['username'] || !$_SESSION['email']){
$username = $_POST['username'];
$password = $_POST['password'];
$username = strip_tags($username);
$password = strip_tags($password);
$ip = $REMOTE_ADDR;
$domain = $_SERVER['REMOTE_ADDR'];

$username=strtolower($username);

if((!$username) || (!$password)){
    echo "You have not submitted one or more fields <br />";
}else{




$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1");
$login_check = mysql_num_rows($sql);



if ($login_check > '1'){





        ini_set(session.cookie_lifetime, "3600");
        session_register('username');
        $_SESSION['username'] = $username;
        session_register('email_address');
        $_SESSION['email_address'] = $email_address;






         $timestamp = time();
$timeout = $timestamp-$timeoutseconds;
$cool = gmdate('Y-m-d h:i:s');
mysql_query("UPDATE user_info SET lastlogin='$cool' WHERE username='$username'");
mysql_query("UPDATE user_info SET online='$timestamp' WHERE username='$username'");

mysql_query("UPDATE user_info SET ip='$domain' WHERE username='$username'");



        ?>
<meta http-equiv="Refresh" content=0;url=index.php>
<?

} else {
    echo "wrong username/password combination or account not yet activated<br />
    <br />";
    include 'splash.php';
}}}
?>

 

If anyone can help me, could you message me and i will give you my sql db and ftp address (serious only please)

Link to comment
https://forums.phpfreaks.com/topic/148287-help-with-a-register-login-form/
Share on other sites

Try

 

mysql_query("INSERT INTO user_info ( 'id' , 'username' , 'password' , 'email' , 'money' , 'bullets' , 'points' , 'health' ,  'rank' , 'rankpoints' , 'weapon' , 'armour' , 'plane' , 'location' , 'ip' , 'userlevel' )
VALUES (
'', '$reg_username', '$randomPass' , '$email' , '10000' , '0' , '0' , '100' , 'Civillian', '0' , 'None' , 'None' , 'None' , '$location' , '$ip' , '1' )";
   } }}}}}

Try

 

mysql_query("INSERT INTO user_info ( 'id' , 'username' , 'password' , 'email' , 'money' , 'bullets' , 'points' , 'health' ,  'rank' , 'rankpoints' , 'weapon' , 'armour' , 'plane' , 'location' , 'ip' , 'userlevel' )
VALUES (
'', '$reg_username', '$randomPass' , '$email' , '10000' , '0' , '0' , '100' , 'Civillian', '0' , 'None' , 'None' , 'None' , '$location' , '$ip' , '1' )";
   } }}}}}

 

That just made it come up with a blank screen

correct way to name variables to insert to  a database.

<?php
mysql_query("INSERT INTO user_info (username,password,email,money,bullets,points,
health,rank , rankpoints , weapon , armour, plane , location , ip, userlevel )
VALUES ('$reg_username', '$randomPass' , '$email' , '10000' , '0' , '0' , '100' , 'Civillian', '0' , 'None' , 'None' , 'None' , '$location' , '$ip' , '1' )";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.