Jump to content

PHP Login


Recommended Posts

  • Replies 58
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

ok

<?php
$host="localhost"; // Host name 
$username="pacifij1_blue"; // Mysql username 
$password="8336994895"; // Mysql password 
$db_name="pacifij1_blue"; // Database name 


// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form 
$callsign = $_POST['callsign']; 
$pwd = $_POST['pwd']; 
$first_name = $_POST['first_name']; 
$last_name = $_POST['last_name']; 


$sql="SELECT * FROM pilot WHERE callsign='$callsign' and pwd='$pwd'";
$result=mysql_query($sql) or die(mysql_error());

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count<0){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("callsign");
session_register("pwd"); 
session_register("first_name"); 
session_register("last_name"); 
header("location:login_success.php");
}
else {
mysql_error();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Loading</title>
</head>

<body>
</body>
</html>
<?php mysql_close(); ?>

Link to comment
Share on other sites

try

<?php
$host="localhost"; // Host name 
$username="pacifij1_blue"; // Mysql username 
$password="8336994895"; // Mysql password 
$db_name="pacifij1_blue"; // Database name 


// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form 
$callsign = $_POST['callsign']; 
$pwd = $_POST['pwd']; 
$first_name = $_POST['first_name']; 
$last_name = $_POST['last_name']; 


$sql="SELECT * FROM pilot WHERE callsign='$callsign' and pwd='$pwd'";
$result=mysql_query($sql) or die(mysql_error());

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count<0){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("callsign");
session_register("pwd"); 
session_register("first_name"); 
session_register("last_name"); 
header("location:login_success.php");
}
else {
mysql_error();
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Loading</title>
</head>

<body>
</body>
</html>
<?php mysql_close(); ?>

 

edit: You forgot a "}" closing bracket after the ELSE

Link to comment
Share on other sites

Try

 

<?php
$host="localhost"; // Host name 
$username="pacifij1_blue"; // Mysql username 
$password="8336994895"; // Mysql password 
$db_name="pacifij1_blue"; // Database name 


// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form 
$callsign = $_POST['callsign']; 
$pwd = $_POST['pwd']; 
$first_name = $_POST['first_name']; 
$last_name = $_POST['last_name']; 


$sql="SELECT * FROM pilot WHERE callsign='$callsign' and pwd='$pwd'";
$result=mysql_query($sql) or die(mysql_error());

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count<0){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("callsign");
session_register("pwd"); 
session_register("first_name"); 
session_register("last_name"); 
header("location:login_success.php");
echo 'Login Worked';
}
else {
mysql_error();
echo 'Login Didnt Work';
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Loading</title>
</head>

<body>
</body>
</html>
<?php mysql_close(); ?>

Link to comment
Share on other sites

Login Didnt Work

 

Thats because of the

 

if($count<0){

 

*dirty look to derrick  :P* jk

 

Try

 

<?php
$host="localhost"; // Host name 
$username="pacifij1_blue"; // Mysql username 
$password="8336994895"; // Mysql password 
$db_name="pacifij1_blue"; // Database name 


// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form 
$callsign = $_POST['callsign']; 
$pwd = $_POST['pwd']; 
$first_name = $_POST['first_name']; 
$last_name = $_POST['last_name']; 


$sql="SELECT * FROM pilot WHERE callsign='$callsign' and pwd='$pwd'";
$result=mysql_query($sql) or die(mysql_error());

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("callsign");
session_register("pwd"); 
session_register("first_name"); 
session_register("last_name"); 
header("location:login_success.php");
echo 'Login Worked';
}
else {
mysql_error();
echo 'Login Didnt Work';
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Loading</title>
</head>

<body>
</body>
</html>
<?php mysql_close(); ?>

 

That little part basically means if $count echos any number under 0, then log the user in

Link to comment
Share on other sites

still didnt work

 

We prevented a bug that may occur in the future, so lets give a pat on our backs. You should print out the username and password from the FORM, and the DB and see if they equal each other...

 

<?php
$host="localhost"; // Host name 
$username="pacifij1_blue"; // Mysql username 
$password="8336994895"; // Mysql password 
$db_name="pacifij1_blue"; // Database name 


// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form 
$callsign = $_POST['callsign']; 
$pwd = $_POST['pwd']; 
$first_name = $_POST['first_name']; 
$last_name = $_POST['last_name']; 


$sql="SELECT * FROM pilot WHERE callsign='$callsign' and pwd='$pwd'";
$result=mysql_query($sql) or die(mysql_error());

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
$row = mysql_fetch_array($result);

echo 'Username Tried: ' .$callsign;
echo 'Password Tried: ' .$pwd.'<br>';

echo 'Username DB: ' .$row['pwd'];
echo 'Password DB: ' .$row['callsign'].'<br>';


if($count > 0){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("callsign");
session_register("pwd"); 
session_register("first_name"); 
session_register("last_name"); 
header("location:login_success.php");
echo 'Login Worked';
}
else {
mysql_error();
echo 'Login Didnt Work';
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Loading</title>
</head>

<body>
</body>
</html>
<?php mysql_close(); ?>

Link to comment
Share on other sites

i don't bother with counts..

 

i just would do...

 

 

$sql="SELECT `id` FROM pilot WHERE callsign='$callsign' and pwd='$pwd'";

$result=mysql_query($sql) or die(mysql_error());

$id= mysql_fetch_array($result);

 

if(empty($id['id'])){

echo failed}

 

if(strlen($id['id']) > 0){

log in

}

 

it doesn't count rows... so if there was more than 1 password and username the same i'd be screwed... but i check for existing user names at registration, so that shouldn't be a problem

Link to comment
Share on other sites

i don't bother with counts..

 

i just would do...

 

 

$sql="SELECT `id` FROM pilot WHERE callsign='$callsign' and pwd='$pwd'";

$result=mysql_query($sql) or die(mysql_error());

$id= mysql_fetch_array($result);

 

if(empty($id['id'])){

echo failed}

 

if(strlen($id['id']) > 0){

log in

}

 

it doesn't count rows... so if there was more than 1 password and username the same i'd be screwed... but i check for existing user names at registration, so that shouldn't be a problem

 

You would prevent that at the registration process, and your method takes a lifetime

Link to comment
Share on other sites

ok php sinsi i did what you said and it did this

Username Tried: BWA1001Password Tried: 833699

Username DB: 833699Password DB: BWA1001

 

Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/pacifij1/public_html/bluewavesvirtual/checklogin.php:27) in /home/pacifij1/public_html/bluewavesvirtual/checklogin.php on line 36

 

Warning: Cannot modify header information - headers already sent by (output started at /home/pacifij1/public_html/bluewavesvirtual/checklogin.php:27) in /home/pacifij1/public_html/bluewavesvirtual/checklogin.php on line 40

Login Worked

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

Link to comment
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.