help with php login script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
benzspida
Forum Newbie
Posts: 3
Joined: Wed Jun 28, 2006 7:00 pm

help with php login script

Post by benzspida »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


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

Code: Select all

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

Code: Select all

<?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();
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Search for your error message on these boards and on google. It has been answered here before. It may have to do with your MySQL client API version being outdated for your MySQL database server version.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your MySQL server doesn't like or know the user and or password you've supplied.
benzspida
Forum Newbie
Posts: 3
Joined: Wed Jun 28, 2006 7:00 pm

Post by benzspida »

thanks sorry about the post
Post Reply