Forum Moderators: coopster

Message Too Old, No Replies

Trying to write a log in script

having a little trouble

         

mylungsarempty

6:29 pm on Nov 19, 2003 (gmt 0)

10+ Year Member



Warning: Wrong parameter count for mysql_result() in /mnt/web_a/d11/s01/b01b9236/www/login.php on line 44

that's the warning i get from the following code... any help?

// Check for existing user
$unique = "SELECT * FROM musicians WHERE username = '$username' AND password = PASSWORD('$userpass')";
$result = mysql_query($unique)or die("that is incorrect".mysql_error());

if (mysql_result($result)) {
echo('that is correct welcome')
}

mysql_close($con);

<P align="right" style="font-size: 11px; color: 888888">
<?php echo $username?><?php echo $userpass?>
</P>
<?php endif;?>

[edited by: jatar_k at 9:26 pm (utc) on Nov. 19, 2003]
[edit reason] condensed code [/edit]

jatar_k

7:38 pm on Nov 19, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



[ca3.php.net...]
mixed mysql_result ( resource result, int row [, mixed field])

you missed the required parameter row

mylungsarempty

8:32 pm on Nov 19, 2003 (gmt 0)

10+ Year Member



i am struggling with trying to write a login script... can anyone suggest a really good , not too complicated tutorial that will help me learn?

jatar_k

9:01 pm on Nov 19, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What exactly is the problem you are having with that one? It seems to be coming along nicely.

maybe try
if (mysql_num_rows($result) == 1) {
instead of
if (mysql_result($result)) {

mylungsarempty

9:14 pm on Nov 19, 2003 (gmt 0)

10+ Year Member



jatar_k ... you are key! i think that did it for me... I'm trying to build this large scale website, and i'm learning the PHP as i go along, kindof on a need to know basis -- it's stressful. Thanks for your help though!

mylungsarempty

9:24 pm on Nov 19, 2003 (gmt 0)

10+ Year Member



Alright, well, the PHP script runs without errors now... but i'm not getting the right result. It isn't checking with the database to see if the username and password are correct... i can type in anything in the fields, and it's just displayed... What am i doing wrong here?:

<?php
$username = isset($_POST['username'])? $_POST['username'] : $_SESSION['username'];
$userpass = isset($_POST['userpass'])? $_POST['userpass'] : $_SESSION['userpass'];
if (!isset($_POST['login'])):
?>
<P align="left">
<FORM action="<?=$_SERVER['PHP_SELF']?>" method="post">
&nbsp; &nbsp; <FONT color="ivory">Username:</FONT><BR>
&nbsp; &nbsp; <INPUT type="text" name="username" maxlength="20" class="bord"><BR>
&nbsp; &nbsp; <FONT color="ivory">Password:</FONT><BR>
&nbsp; &nbsp; <INPUT type="password" name="userpass" maxlength="20" class="bord"><BR>
&nbsp; &nbsp; <INPUT type="submit" name="login" value="log in" style="height: 22px; width: 44px; font-size: 9px; font-weight: bold; font-family: Arial; border: 2px double ivory" onFocus="if(this.blur)this.blur()"><BR>
</FORM>
</P>
<?php

else:
mysql_select_db($db, $con);
if ($_POST['username']=='' or $_POST['userpass']=='') {
error('One or more required fields were left blank.\\n'.
'Please fill them in and try again.');
}
// Check for existing user
$unique = "SELECT * FROM musicians WHERE username = '$username' AND password = PASSWORD('$userpass')";
$result = mysql_query($unique)or die("that is incorrect".mysql_error());
if (mysql_num_rows($result) == 1) {
error('that is correct.\\n'.
'congrats.');
}
mysql_close($con);
if (mysql_num_rows($result) == 0) {

unset($_SESSION['username']);

unset($_SESSION['userpass']);

}
?>
<P align="left" style="font-size: 11px; color: 888888">
Welcome, <?php echo $username?>.<BR><BR><?php echo $userpass?>
</P>
<?php endif;?>

coopster

10:08 pm on Nov 19, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Try exiting your script right after you build the query statement to see if your statement looks like you expect:

$unique = ...
exit($unique); // add this line to check your statement out.
$result = ...