Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 17th, 2006, 11:41 AM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Authentication coding help

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 'ODBC'@'localhost' (using password: NO) in C:\Webroot\checklogin.php on line 10
cannot connect )

This is what the Script looks like :

Table

Create Table 'members' (
'id' int(4) NOT NULL auto_increment,
'f_name' varchar(50) NOT NULL default",
'l_name' varchar(50)NOT NULL default",
'username' varchar(10) NOT NULL default",
'password' varchar(10) NOT NULL default",
PRIMARY KEY ('id')
)TYPE=MyISAM AUTO_INCREMENT=2;
--
-- Dumping data for table 'members'
--
INSERT INTO 'members' VALUES ('john','1234');

Login

<?php
ob_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // 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['mypassword'];

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

ob_end_flush();
?>

 
Old April 20th, 2006, 10:43 AM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, it seems to me that your $username and $password are not correct as that's what that warning message is all about.

If you installed a test DB on your localhost, try setting $username to "root". If that doesn't help then you must find out what's the user name and password for the DB you want to connect to.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding Help sugunakar Classic ASP Professional 2 March 30th, 2008 04:42 PM
help with coding mastrgamr C++ Programming 15 November 10th, 2006 07:55 AM
Help coding here Scoob PHP How-To 3 January 26th, 2006 11:18 AM
can someone help me in coding this? somanchivasu Access 1 April 5th, 2004 02:41 PM
Authentication Coding Help CMensah Classic ASP Basics 1 December 1st, 2003 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.