Jump to content

Login prob

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Flezria

Flezria

    Learning Programmer

  • Members
  • PipPipPip
  • 55 posts
i got this problem with my loginsystem. its saying that there is a fail in the code that i cant see. im pretty new to php and i will like to get some help :) the code is:

<html>


<head>


</head>


<body>


<?php

$con = mysql_connect('localhost','*****','*****');

if (!$con) {

 die ('could not connect: ' . mysql_error());

 }


$select_db=mysql_select_db("*****", $con);


if(!$select_db) {

	die ('could not connect to db: ' . mysql_error());

}


$username =  $_POST['username'];

$password =  $_POST['password'];


$sql="SELECT username FROM LogIn WHERE username=".$username." and password=".$password;

$err=mysql_error();

$result=mysql_query($sql);


if(!$sql) {

	echo $err;

}


if(!mysql_num_rows($result)) {

echo "username or password is wrong";

}

else {

echo "Login successful";

}



?>


</body>


</html>

the problem is Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource. on line 32 wich is if(!mysql_num_rows($result)). thanks alot :)

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Please read http://forum.codecal...issues-php.html.

#3
Flezria

Flezria

    Learning Programmer

  • Members
  • PipPipPip
  • 55 posts
Thanks alot for the link, i tryed the debugging but i can really not see the prob :crying:

#4
Jacki

Jacki

    Learning Programmer

  • Members
  • PipPipPip
  • 80 posts
try this:
<?php

$con = 	mysql_connect('localhost','root','') 

		or die ('could not connect: ' . mysql_error());


$db = 	mysql_select_db("dev", $con)

		or die ('could not connect to db: ' . mysql_error());


$query = "SELECT username FROM LogIn WHERE username='".$_POST['username']."' AND password='".$_POST['password']."'";

$result = mysql_query($query);


if(!mysql_num_rows($result)) {

	echo "username or password is wrong";

} else {

	echo "Login successful";

}

?>
I wrote it quickly and I don't know if it work correctly, let me know... bye!

#5
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts

Flezria said:

Thanks alot for the link, i tryed the debugging but i can really not see the prob :crying:

What is the value of $result?

#6
Flezria

Flezria

    Learning Programmer

  • Members
  • PipPipPip
  • 55 posts
thanks alot! its worked. just got osme other probs now ;). but i will try solve them by myself so i can learn more :D thanks alot again.:thumbup1:

#7
Jacki

Jacki

    Learning Programmer

  • Members
  • PipPipPip
  • 80 posts
I think the error was in the mysql query, you have to put '' after the =...

bye-bye! :thumbup: