Jump to content

Recommended Posts

Hi to All.. Im Uday, Im new to PHP, actually i plan to do a register page,  i have a problem in Login page, if i once register its goes to login page, here in login im going to check the valid name and password, if i click the login button, its reset the page, plz help me to let out.. here the code follows..

Login.PHP

<?php

 

include 'config.php';

 

ob_start();

echo "<center><font size\"2\" face=\"Tahoma\"> Network-13 Login System </font></center><br>";

echo "Login..<br>";

echo "<form action=\"./login.php\" method=\"POST\">";

echo "Name: <br><input type=\"text\" name=\"username\"><br>";

echo "Your email: <br><input type=\"text\" name=\"email\"><br>";

echo "Pass: <br><input type=\"password\" name=\"password\"><br>";

echo "<input type=\"submit\" value=\"Login!\">";

echo "</form>";

echo "<br>Dont have an account? Register <a href=\"register.php\">here!</a>";

echo "<br>Forgot your password? Click <a href=\"reset.php\">here!</a>";

 

$connection = @mysql_connect($hostname, $user, $pass)

or die(mysql_error());

$dbs = @mysql_select_db($database, $connection) or

die(mysql_error());

 

$sql = "SELECT * FROM `users` WHERE username = '$_POST[username]' AND password = '$_POST[password]' AND email = '$_POST'";

$result = @mysql_query($sql,$connection) or die(mysql_error());

$num = @mysql_num_rows($result);

echo $num;

if ($num != 0) {

$cookie_name = "auth";

$cookie_value = "fook";

$cookie_expire = "0";

$cookie_domain = $domain;

 

setcookie($cookie_name, $cookie_value, $cookie_expire, "/", $cookie_domain, 0);

header ("Location: http://" . $domain  . $directory . "admin.php");

 

ob_end_flush();

 

exit;

}

?>

*****************************

Register.php

<?php

 

include 'config.php';

 

function is_alphachar($text) {

 

    for ($i = 0; $i < strlen($text); $i++) {

   

    if (!ereg("[A-Za-z0-9]", $text[$i])) {

    return 1;

    }

    }

    }

 

$form .= "Register a new username. Be sure to enter a <b>genuine</b> email as it will be used to recover your account.<br>";

$form .= "<form action=\"./register.php\" method=\"POST\">";

$form .= "Username: <br><input type=\"text\" name=\"username\"><br>";

$form .= "Your email: <br><input type=\"text\" name=\"email\"><br>";

$form .= "Password: <br><input type=\"password\" name=\"password\"><br>";

$form .= "<input type=\"submit\" value=\"Create!\">";

$form .= "</form>";

 

if($_POST[username] == "")

{

echo $form;

}

elseif(strlen($_POST[password]) < 6)

{

echo $form;

echo "<br> Error password must be 6 characters or more";

}

else

  {

$connection = mysql_connect($hostname, $user, $pass)

or die(mysql_error());

$db = mysql_select_db($database, $connection)

or die(mysql_error());

 

 

$sql = "SELECT username FROM users

WHERE username = '$_POST[username]'";

 

$sql2 = "SELECT email FROM users

WHERE email = '$_POST'";

 

$result = mysql_query($sql)

or die ("Couldn't execute query.");

 

$result2 = mysql_query($sql2)

or die ("Couldn't execute query.");

 

$num = mysql_num_rows($result);

$num2 = mysql_num_rows($result2);

 

if (is_alphachar($_POST[username]) == 1)

{

echo $form;

echo "Invalid Username. Only numbers/letters and underscores are allowed.<br>";

die;

}

if ($num == 1)

{

echo "Error, username already exists!";

echo "<br><a href=\"register.php\">Back to Register Area</a>";

}

elseif ($num2 == 1){

echo "Error, that email address has already been registered. Please select a different one.";

echo "<br><a href=\"register.php\">Back to Register Area</a>";

}

else

  {

 

$query = "INSERT INTO users (username,password,email)

VALUES ('$_POST[username]','$_POST[password]','$_POST')";

$resultB = mysql_query($query,$connection) or die ("Coundn't execute query.");

echo "Congratulations $tmpname. Your account has been created and added to database";

echo "<br><a href=\"login.php\">Back to login area</a>";

}

}

?>

Link to comment
https://forums.phpfreaks.com/topic/53365-problem-in-login-page/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.