SunQuest
 
           General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 16th, 2005, 01:25 PM
mr_roll mr_roll is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 mr_roll User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 14 sec
Reputation Power: 0
Having problems with SQL authentication

{edit}
Posted in correct forum
{/edit}

Hiya, Having problems with http://www.devarticles.com/c/a/MySQL/PHP-MySQL-and-Authentication-101/3/

I'm using WAMP.

Code:

<HTML>
<HEAD>
<TITLE>MY PAGE</title>
</HEAD>
<BODY>

<?PHP 

$db = mysql_connect('localhost', 'user', '1234') or die("Couldn't connect to the database."); 
mysql_select_db('mydatabase') or die("Couldn't select the database"); 

// Add slashes to the username, and make a md5 checksum of the password. 
$_POST['user'] = addslashes($_POST['user']); 
$_POST['pass'] = md5($_POST['pass']); 

$result = mysql_query("SELECT count(id) FROM users WHERE password='$_POST[pass]' AND 

username='$_POST[user]'") or die("Couldn't query the user-database."); 
$num = mysql_result($result, 0); 

if (!$num) { 

// When the query didn't return anything, 
// display the login form. 

echo "<h3>User Login</h3> 
<form action='$_SERVER[PHP_SELF]' method='post'> 
Username: <input type='text' name='user'><br> 
Password: <input type='password' name='pass'><br><br> 
<input type='submit' value='Login'> 
</form>"; 

} else { 

// Start the login session 
session_start(); 

// We've already added slashes and MD5'd the password 
$_SESSION['user'] = $_POST['user']; 
$_SESSION['pass'] = $_POST['pass']; 

// All output text below this line will be displayed 
// to the users that are authenticated. Since no text 
// has been output yet, you could also use redirect 
// the user to the next page using the header() function. 
// header('Location: page2.php'); 

echo "<h1>Congratulations</h1>"; 
echo "You're now logged in. Try visiting <a href='page2.php'>Page 2</a>."; 

} 

?>

</BODY>
</HTML>


When I go to login.php I get "Couldn't query the user-database."

My database is called "mydatabase" and my table is called "user" my user name is "user" and password is "1234"

How could I fix this ?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Having problems with SQL authentication


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway