Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > PHP
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 07-05-2006, 02:35 PM   #1 (permalink)
benzspida
Registered User
 
Join Date: Jun 2006
Posts: 10
benzspida is on a distinguished road
help with php login script

Trying to create an authentication and tracking script . but when ever I run the script I keep getting an error message(

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'john'@'localhost' (using password: YES) in C:\Webroot\Authen1\checklogin.php on line 10
cannot connect


here is my code

<?php
ob_start();
$host="localhost"; // Host name
$username="john"; // Mysql username
$password="1234"; // Mysql password
$db_name="dbUsername"; // Database name
$tbl_name="Authenticate"; // Table 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");

// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['myusername'];

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

// 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("myusername");
session_register("myusername");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}

ob_end_flush();
?>
benzspida is online now Edit/Delete Message
__________________
benzspida is offline   Reply With Quote
Old 07-05-2006, 10:28 PM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 637
DJMaze is on a distinguished road
How did you setup MySQL?
The issue is your MySQL setup not PHP.
__________________
DJMaze is offline   Reply With Quote
Old 07-06-2006, 09:23 AM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
to give user 'john@localhost' permission, you should login to mysql as root and execute the following command:
Code:
GRANT ALL PRIVILEGES ON dbUsername.* TO john@localhost IDENTIFIED BY 'somepassword';
__________________
testing 1 2 3
sde is online now   Reply With Quote
Old 07-06-2006, 09:24 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
on second thought, it looks like you did that, but the quotes got in as part of the username and host maybe?
Quote:
john'@'localhost
__________________
testing 1 2 3
sde is online now   Reply With Quote
Old 07-06-2006, 12:02 PM   #5 (permalink)
benzspida
Registered User
 
Join Date: Jun 2006
Posts: 10
benzspida is on a distinguished road
thanks for the help
__________________
benzspida is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing a php script when receiving an e-mail? Redline Lounge 1 11-15-2005 11:07 PM
Login Script against two tables BUFFY PHP 33 06-18-2005 01:45 PM
Trouble with PHP Login Script JimAdkins PHP 14 03-19-2005 02:40 PM
Executing a server script from PHP sde PHP 4 02-05-2005 11:12 AM
login script trevor PHP 21 01-17-2003 06:28 AM


All times are GMT -8. The time now is 11:53 AM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle