Jump to content

Recommended Posts

Hi. can someone help me with my login? it wont work..

The error message is this:

"Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\Main Login Page2.php on line 17

the server made a boo boo"

 

 

<html>

<head>

<titel>Main Login Page</titel>

<style type="text/css"> </style>

</head>

<body>

 

<div id="loginform">

<form method ="post" action=

<?php

$host = "localhost";

$username = "";

$passowrd = "";

$db_name = "test";

$tbl_name = "members";

 

mysql_connect ($host, $username, $password) or die ("the server made a boo boo");

mysql_select_db (db_name) or die (mysql_error () );

 

$myusername = $_POST ['myusername'];

$mypassowrd = $_POST ['mypassword'];

 

$sql = "SELECT * FROM $members WHERE username='$myusername' and password='$mypassword'";

$result = mysql_query($sql);

 

$count = mysql_num_rows ($result);

 

if($count ==1) {

session_register ("myusername");

session_register ("mypassowrd");

header("location:login_success.php");

}

else {

echo "Wrong Username or Password";

}

?>

 

<label for="username">Username:</label>

<input type"text" name="myusername" id="username" />

<label for="password">Password:</label>

<input type="password" name="mypassword" id="password" />

<input type="submit" name="submit" value="Login" />

 

 

</form>

</div>

</body>

</html>

 

 

 

i attatched a picture of my database

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/
Share on other sites

i dont know how to help but was wondering if you could help me?

 

<p align="center"><a style="text-decoration: none" href="support.html">Customer Service</a> | <a style="text-decoration: none" href="Top%2040.html">Top 40</font></a> | <a style="text-decoration: none" href="home.html">Home</a> | <a style="text-decoration: none" href="videos.php">Videos</a> | <a style="text-decoration: none" href="logout.php">Logout</a>
<div align="center"><img src="images/whitenoise.jpg"></div>
<title>White Noise | Members</title>
<div align="center"><h3>The members area will be updated at a later date,
<p>Thank you for your patience,</p>
<p>White Noise</p></div>

 

i want it so if your not logged on you cant view the members page where as now you can just view members page without being logged in. can you help ?

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985358
Share on other sites

You can check sessions, such as so

if ($_SESSION['myusername'] == false) {
    header('Location: Login.php'); //Redirect them if they're not logged in.
}

 

Also, What is your PHP version? session_register() is depricated and will NOT work as expected in PHP >=5.3, you must assign as $_SESSION['key'] = 'value'

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985360
Share on other sites

You can check sessions, such as so

if ($_SESSION['myusername'] == false) {
    header('Location: Login.php'); //Redirect them if they're not logged in.
}

 

Also, What is your PHP version? session_register() is depricated and will NOT work as expected in PHP >=5.3, you must assign as $_SESSION['key'] = 'value'

 

 

im using the latest WAMP server

and i got PHP 5.3.0

and mysql 5.1.36

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985364
Share on other sites

The error says it all.. Your username and/or password is incorrect for connection to mysql.. check that they are correct.

or create a new user with access to the database you are trying to connect to..

 

as you might figured, i have no idea of what im doing.. i found this nice tutorial and though "its just copy and paste! " but it wassent.. witch i supose is good becouse im lerning!

 

but culd you tell me what i need to do, i made a user that is allowed everywere. but it still dosent work..

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985366
Share on other sites

ignace: too true..

as for this topic..

mysql_select_db (db_name) or die (mysql_error () );

needs to be

mysql_select_db ($db_name) or die (mysql_error () );

 

And as for the main error..

When you created the mysql database did you create a username or password?

 

Just gonna throw this out there.. set your $username to 'root'

 

$host = "localhost";
$username = "root";
$password = "";
$db_name = "test";
$tbl_name = "members";

mysql_connect ($host, $username, $password) or die ("the server made a boo boo");
mysql_select_db ($db_name) or die (mysql_error () );

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985375
Share on other sites

@Buddski

 

i think it works...cus i got some new errors...

 

Main Login Page

Notice: Undefined variable: password in C:\wamp\www\Main Login Page2.php on line 17

 

Notice: Undefined index: myusername in C:\wamp\www\Main Login Page2.php on line 20

 

Notice: Undefined index: mypassword in C:\wamp\www\Main Login Page2.php on line 21

 

Notice: Undefined variable: members in C:\wamp\www\Main Login Page2.php on line 23

 

Notice: Undefined variable: mypassword in C:\wamp\www\Main Login Page2.php on line 23

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Main Login Page2.php on line 26

Wrong Username or Password

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985379
Share on other sites

As buddski has mentioned, try the default mysql user/pass: root with no password. I believe WAMP would of asked you for a password for the root user.

 

If not, then download the MySQL GUI Tools, google "MySQL Windows Password Reset" if you cannot get into mysql GUI Tools.

 

Also, make sure you spell everything correctly, it will help later if you dont know how to spell things you wont know what variables are what. Anything you dont know just get a dictionaryt out or use one online.

 

-CB-

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985380
Share on other sites

Ok lets work through these errors

They all basically say 'You cant use that.. It doesnt exist...'

Err #1: $password variable definition is spelt incorrectly you have $passowrd

Err #2: Lines 20 and 21 are POST values which dont exist.. check to see what the form is posting.

Err #3: You dont even have a members variable defined change where is has $members to $tbl_name

Err #4: You spelt $mypassword incorreclty again..

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985385
Share on other sites

Ok lets work through these errors

They all basically say 'You cant use that.. It doesnt exist...'

Err #1: $password variable definition is spelt incorrectly you have $passowrd

Err #2: Lines 20 and 21 are POST values which dont exist.. check to see what the form is posting.

Err #3: You dont even have a members variable defined change where is has $members to $tbl_name

Err #4: You spelt $mypassword incorreclty again..

 

 

ok iv fixed all but those post things.. what whuld i do with those? :S

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985387
Share on other sites

@Buddski

 

emn.. Form.. hmm..  il just show you the entire thing cus i dont know what your looking for...

This is: login_success

<?
session_start();
if(!session_is_registered(myusername)) {
header("location:mainlogin.php);
}
?>

<html>
<head><title>Welcome</title>
</head>
<body>
<h1> Login was Successful<h1>

<p>
<a href="logout.php">Log Out!</a></p>
</body>
</html>

 

This is logg out

<?
session_start();
session_destroy();
?>

<html>
<head><title>Thanks</title>
</head>
<body>
<h1>You've Logged Out</h1>
</body>
</html>

 

and this is the main page ( the one iv showed allready..)

<html>
<head>
<titel>Main Login Page</titel>
<style type="text/css"> </style>
</head>
<body>

<div id="loginform">
<form method ="post" action=
<?php
$host = "localhost";
$username = "root";
$password = "";
$db_name = "test";
$tbl_name = "members";

mysql_connect ($host, $username, $password) or die ("the server made a boo boo");
mysql_select_db ($db_name) or die (mysql_error () );

$myusername = $_POST ['myusername'];
$mypassword = $_POST ['mypassword'];

$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($sql);

$count = mysql_num_rows ($result);

if($count ==1) {
session_register ("myusername");
session_register ("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

<label for="username">Username:</label>
<input type"text" name="myusername" id="username" />
<label for="password">Password:</label>
<input type="password" name="mypassword" id="password" />
<input type="submit" name="submit" value="Login" />


</form>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985398
Share on other sites

Ok I see..

<?php
$message = '';
if (isset($_POST['submit'])) {
$host = "localhost";
$username = "root";
$password = "";
$db_name = "test";
$tbl_name = "members";

mysql_connect ($host, $username, $password) or die ("the server made a boo boo");
mysql_select_db ($db_name) or die (mysql_error () );

$myusername = $_POST ['myusername'];
$mypassword = $_POST ['mypassword'];

$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($sql);

$count = mysql_num_rows ($result);

if($count ==1) {
session_start();
$_SESSION['myusername'] = $_POST['myusername'];
$_SESSION['logged_in'] = true;
header("location:login_success.php");
}
else {
$message = "Wrong Username or Password";
}
}
?>

<html>
<head>
<titel>Main Login Page</titel>
<style type="text/css"> </style>
</head>
<body>

<div id="loginform">
<form method ="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<label for="username">Username:</label>
<input type"text" name="myusername" id="username" />
<label for="password">Password:</label>
<input type="password" name="mypassword" id="password" />
<input type="submit" name="submit" value="Login" />
<br/>
<?php echo $message; ?>
</form>
</div>
</body>
</html>

Might work a little better for your main script

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985400
Share on other sites

I see that.

change

$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($sql);

$count = mysql_num_rows ($result);

if($count ==1) {
session_start();
$_SESSION['myusername'] = $_POST['myusername'];
$_SESSION['logged_in'] = true;
header("location:login_success.php");
}
else {
$message = "Wrong Username or Password";
}
}

to

$sql = "SELECT * FROM $tbl_name WHERE username='$myusername'";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
$data = mysql_fetch_assoc($result);
if ($data['password'] == $mypassword) {
	session_start();
	$_SESSION['myusername'] = $_POST['myusername'];
	$_SESSION['logged_in'] = true;
	header("Location: login_success.php");
} else {
	$message = 'Username/Password combination incorrect';
}
} else {
$message = 'Username/Password combination incorrect';
}

 

You may also want to look into hashing your passwords too.

Look at md5 in the php manual.

Link to comment
https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985421
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.