Jump to content

[SOLVED] a log in problem


littlepeg

Recommended Posts

You are right, how come the passwords have different code? Is it something to do with my registration form?

 

The following error(s) occurred: - The user name and password entered do not match those on file. - Query: SELECT user_id, first_name FROM users WHERE user_name='tom' AND password='34b7da764b21d298ef307d04d8152dc5'

 

--

-- Table structure for table `users`

--

 

CREATE TABLE `users` (

  `user_id` int(10) unsigned NOT NULL auto_increment,

  `user_name` varchar(25) NOT NULL,

  `password` varchar(32) NOT NULL,

  `first_name` varchar(15) NOT NULL,

  `last_name` varchar(30) NOT NULL,

  `address` varchar(100) NOT NULL,

  `postcode` varchar(12) NOT NULL,

  `tel` varchar(20) NOT NULL,

  `email` varchar(100) default NULL,

  `agreetolist` varchar(4) NOT NULL,

  `registration_date` datetime NOT NULL,

  PRIMARY KEY  (`user_id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=25 ;

 

--

-- Dumping data for table `users`

--

 

INSERT INTO `users` (`user_id`, `user_name`, `password`, `first_name`, `last_name`, `address`, `postcode`, `tel`, `email`, `agreetolist`, `registration_date`) VALUES

(11, 'ttt', '96835dd8bfa718bd6447ccc87', 'a', 'a', 'a', 'sr5', 'a', 'a', 'y', '2007-05-04 23:47:25'),

(12, 'fasd', 'c4ca4238a0b923820dcc509a6', '1', '1', '1', 'sr5', 's', 's', 'y', '2007-05-05 00:06:45'),

(13, 'e', '58e6b3a414a1e090dfc6029add0f3555', 'e', 'e', 'e', 'peggyzhao@ho', 'e', '[email protected]', 'y', '2007-05-05 00:14:40'),

(14, 't', '8efd86fb78a56a5145ed7739dcb00c78', 't', 't', 't', 'peggy@hotmai', 't', '', 'y', '2007-05-05 00:16:50'),

(15, 'g', 'b2f5ff47436671b6e533d8dc3614845d', 'g', 'g', 'g', 'sr5', 'g', 'h', 'y', '2007-05-05 00:21:35'),

(16, 'u', '51e69892ab49df85c6230ccc57f8e1d1', 'u', 'u', 'u', 'sr5', 'u', '[email protected]', 'y', '2007-05-05 00:23:24'),

(17, 'p', 'p', 'p', 'p', 'p', 'sr5', 'p', '[email protected]', 'y', '2007-05-05 01:35:08'),

(18, 'user', 'pass', '', '', '', '', '', NULL, '', '0000-00-00 00:00:00'),

(19, 'user', 'pass', '', '', '', '', '', NULL, '', '0000-00-00 00:00:00'),

(20, 'user', 'pass', '', '', '', '', '', NULL, '', '0000-00-00 00:00:00'),

(21, 'user', 'pass', '', '', '', '', '', NULL, '', '0000-00-00 00:00:00'),

(22, 'user', 'pass', '', '', '', '', '', NULL, '', '0000-00-00 00:00:00'),

(23, 'user', 'pass', '', '', '', '', '', NULL, '', '0000-00-00 00:00:00'),

(24, 'tom', '96835dd8bfa718bd6447ccc87af89ae1', 'a', 'a', 'a', 'sr5', 'a', '[email protected]', 'y', '2007-05-05 02:35:26');

 

your problem is user id (auto increment( and username? which one do you compared? you try omit the auto increment since username already UNIQUE and could be set as primary key.

 

try this:

 

<?php
if (empty($errors)) { // If everything's OK.

            $query = "SELECT user_name, first_name FROM users WHERE user_name='$un' AND password='$p'";      
      $result = mysql_query($query) or die(mysql_error());
       // Run the query.
      $row = mysql_num_rows($result); // Return a record, if applicable
?>

 

Before you try this, modify your DB design. Omit the auto increment user_id which in my opinion is redundant field.

your problem is user id (auto increment( and username? which one do you compared? you try omit the auto increment since username already UNIQUE and could be set as primary key.

 

try this:

 

<?php
if (empty($errors)) { // If everything's OK.

            $query = "SELECT user_name, first_name FROM users WHERE user_name='$un' AND password='$p'";      
      $result = mysql_query($query) or die(mysql_error());
       // Run the query.
      $row = mysql_num_rows($result); // Return a record, if applicable
?>

 

Before you try this, modify your DB design. Omit the auto increment user_id which in my opinion is redundant field.

 

yes that is an issue, however thats not why the query isn't working....

thank you for all your help. benjaminbeazy and tauchai83, you are all very very nice. I just found out where was the problem, in my registration form I used SHA() to encrypt the password (I thought I changed it to md5(), but I didnt, there were too much tried versions for the registration form, so all mixed up), and in the log in form I used md5(). So now, I changed SHA() to md5(), and also used benjaminbeazy, your last codes, they work fine now. Thank you very much for your time.  :) :) :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.