php sql password nightmare!

runs sql , always returns row less then zero ie. echo"ohh crap&

Page 1 of 1

4 Replies - 1260 Views - Last Post: 16 December 2009 - 03:53 PM Rate Topic: -----

#1 adgentdarkbooty   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-November 09

php sql password nightmare!

Post icon  Posted 30 November 2009 - 06:04 PM

<?php
//---------------------------------------------------------------------------------------------------------------------------------------->
	function check_user_info()
	{
	$error = '';
	//check user against database
	//and password any problems add to error.


		if($error)					//if error is exists do this
		{
			display_login_page($error);
		}
		else						//if it doesnt exist do this
		{
//------------------------------------------------------------------------------------------------------------------------------------------->
			$self	   = $_SERVER['PHP_SELF'];
			$name	   = $_REQUEST['name'];
			$password   = $_REQUEST['password'];
			$login	  = $_REQUEST['login'];
			$email	  = $_REQUEST['email'];
			//$comments = $_REQUEST['comments'];
			//$time	 = $_REQUEST['time'];


			$query = "INSERT INTO usertb(name,userlogin,pword,email) VALUES
			(\"$name\",\"$login\",password('$password'),\"$email\")";

			$result = mysql_query($query) or die("<br> Error encountered.<br>username already taken");

			if($result)
			{
				echo"Thank you ".$login.", your account has been set up <br></p>";
				echo"<br><a href='firstpage.php'>login here</a><br>";
				mysql_close();
			}






//------------------------------------------------------------------------------------------------------------------------------------------->
		}



	}

?>






<?php

 function check_user_info()
 {
//------------------------------------------------------------------------------------------------------------------------------------------->

 $error = '';
 //check user against database
 //and password any problems add to error.


  if($error)	 //if error is exists do this
  {
   display_login_page($error);
  }
  else	  //if it doesnt exist do this
  {

   $self	   = $_SERVER['PHP_SELF'];
   $name	   = $_REQUEST['name'];
   $password   = $_REQUEST['password'];
   $login	  = $_REQUEST['login'];
   $email	  = $_REQUEST['email'];
   //$comments = $_REQUEST['comments'];
   //$time	 = $_REQUEST['time'];

	echo"<br>password : \"$password\"<br>login:\"$login\"";

	  $query ="SELECT * FROM usertb WHERE userlogin ='$login'  AND pword = password('$password')";
	$result = mysql_query($query) or die("<br> Error encountered.<br>recheck details");

   //RIPPED RIGHT FROM LECTURE NOTES
  $numrows = mysql_num_rows($result); // basically numrows is 0 when no matchs and 1 when 1 2 when 2 and so on


  if($numrows == 1)
  {

   $_SESSION['valid_user'] = $login;
   $_SESSION['authenticated'] = true;
   mysql_free_result($result);
   mysql_close();
   //a user has successfully logged in and is directed to the members area

   echo"<br>sweetSuccess";

  }
  else
  {
   echo "<br>oh crap...";
  }




  }



//------------------------------------------------------------------------------------------------------------------------------------------->
 }

?>






ok , the first method is how i get info into the database.
i checked my database and it goes in fine.

in the second method is the problem, when i check if the user is in the data base
when i deleted the second part of the sql statement (password stuff) it worked fine.
is there something wron with the second methods query maybe encryption or something?
i feel i know what the problem is just can't fix it.

This post has been edited by CTphpnwb: 30 November 2009 - 07:32 PM


Is This A Good Question/Topic? 0
  • +

Replies To: php sql password nightmare!

#2 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3796
  • View blog
  • Posts: 13,742
  • Joined: 08-August 08

Re: php sql password nightmare!

Posted 30 November 2009 - 07:34 PM

1) Please use Code tags!

2) Try it this way:
	  $query ="SELECT * FROM usertb WHERE userlogin ='$login'  AND pword ='$password'";


Was This Post Helpful? 0
  • +
  • -

#3 adgentdarkbooty   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-November 09

Re: php sql password nightmare!

Posted 15 December 2009 - 08:53 AM

The problem was that my database field in my sql database wasn't big enough.
I thought 40 chars would be enough, duh!
Was This Post Helpful? 0
  • +
  • -

#4 RawrItsAdam   User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 72
  • Joined: 10-November 08

Re: php sql password nightmare!

Posted 16 December 2009 - 04:07 AM

View Postadgentdarkbooty, on 15 Dec, 2009 - 02:53 PM, said:

The problem was that my database field in my sql database wasn't big enough.
I thought 40 chars would be enough, duh!


haha glad you solved it, only the other day I had the same problem, except I was encrypting the password using MD5 which takes 32 chars and my database was set to 30, easy done :)
Was This Post Helpful? 0
  • +
  • -

#5 ghqwerty   User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

Re: php sql password nightmare!

Posted 16 December 2009 - 03:53 PM

omg, its adam, he's actually on this site, omg heart attack, lol

[/off topic]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1