Page 1 of 1

need help with PHP mysql, please need some advce.

Posted: Tue Dec 09, 2008 2:47 am
by dfgdgdfgdfg
for some reason my code do not return any value. it is a simple login script. just check the username and password.

*****this is my php page NAME: auth1.php**************

Code: Select all

<html>
<body>
<?
$user = $_POST['user']; //post user name
$pass = $_POST['pass']; // post pass
 
 
 
$connection = mysql_connect(localhost, "", "");
mysql_select_db('login') or die("cannot select a database");
 
$get = mysql_query(SELECT * FROM login_info WHERE usr = '$user' and pass = '$pass'); 
$result =mysql_result($get, 0);
$close = mysql_close($connection);
 
if ($result != 1) echo "login failure";
else {
echo "Suceess";
};
 
 
?>
</body>
</html>
----------------------------------------------------------
******this is my form page : login_page.php ***********************

Code: Select all

<form action="auth1.php" method="post" name= "form1">
 
User name <input type="text" name = "user" />
Password <input type="text" name = "pass" />
<input type="submit" value = "submit" />
</form>
please help

Re: need help with PHP mysql, please need some advce.

Posted: Tue Dec 09, 2008 3:17 am
by requinix
You can't even bother creating a decent username.

Code: Select all

$get = mysql_query(SELECT * FROM login_info WHERE usr = '$user' and pass = '$pass');
There's the problem.

Re: need help with PHP mysql, please need some advce.

Posted: Tue Dec 09, 2008 3:37 am
by dfgdgdfgdfg
in my code, in line 12, i already wrote that line you suggested. still not working, please help.

Re: need help with PHP mysql, please need some advce.

Posted: Tue Dec 09, 2008 4:29 am
by requinix
dfgdgdfgdfg wrote:in my code, in line 12, i already wrote that line you suggested. still not working, please help.
Not a very good suggestion when it's accompanied by the words "there's the problem". It was more like I pointed out that there's something wrong with it.

If you have a reasonable amount of PHP experience you should be able to look at the code and see what's wrong with it. There's even some highlighting to help you (hint: the query should be in red).
And yes, I'm biased against you.

Re: need help with PHP mysql, please need some advce.

Posted: Tue Dec 09, 2008 3:15 pm
by dfgdgdfgdfg
it is not nice of you that you were biased againt me just because I have poor knowledge of PHP. you can just explain what the problem in my code rather than critisizing my ability, it would have been nice. thanks

Re: need help with PHP mysql, please need some advce.

Posted: Tue Dec 09, 2008 4:40 pm
by requinix
dfgdgdfgdfg wrote:it is not nice of you that you were biased againt me just because I have poor knowledge of PHP. you can just explain what the problem in my code rather than critisizing my ability, it would have been nice. thanks
No, I'm biased against you because when signing up for this site you put no effort into creating a username and simply hit the letters d, f, and g repeatedly.

Fine.

Code: Select all

$get = mysql_query(SELECT * FROM login_info WHERE usr = '$user' and pass = '$pass');
The query should be a string. Since it is not a string PHP thinks it's code. Which it is not. It has a fit over it and complains.

Code: Select all

$get = mysql_query("SELECT * FROM login_info WHERE usr = '$user' and pass = '$pass'");
See the change in highlighting?

Re: need help with PHP mysql, please need some advce.

Posted: Tue Dec 09, 2008 5:53 pm
by cedartree
i agree with you tasairis,
nonetheless,
has this guy even run the query on his mysql database in order to create the username / password?

also, is the php file linked in to access the database?