Question

Not sure how much context I can provide. I just tried to do overdue homework and I get the error: Its supposed to be a simple login page, login check and loginsuccess and failure.

on check.php:

Warning: Wrong parameter count for mysql_query() in /u/students/j/j.d.dancks/public_html/cis231/hw/hw5/check.php on line 11

I thought I knew what I was doing I guess not.

code:

<?php
$good = false;
if(array_key_exists('nick',$_POST)&&array_key_exists('pass',$_POST))
{
    if(isset($_POST['nick'])&&isset($_POST['pass']))
    {
        $con = mysql_connect('localhost','heh','heh');
        mysql_select_db('heh_db',$con);
        $q = mysql_query(sprintf("select * from reg_users where username='%s' and pass='%s'",
        mysql_real_escape_string($_POST['nick']),
        mysql_real_escape_string($_POST['pass'])),$con) or die(mysql_query());
        if(mysql_num_rows($q)==1)
        {
            $good=true;
            $r = mysql_fetch_assoc($q);
            session_start();
            $_SESSION['user'] = $r['username'];
            $_SESSION['lastlogin'] = time();
            mysql_close($con);
            header('loginsuccess.php');
        }
        else
        {
            header('loginfailure.html');
        }
    }
    else
    {
        header('hw5.html');
    }
}
if(!$good)
{
    header('hw5.html');
}
?>
Était-ce utile?

La solution

You need at least a query parameter for mysql_query(). I believe what you want is mysql_error().

change or die(mysql_query()) to or die(mysql_error())

Autres conseils

2nd mysql_query() has no parameter

try using another concatenation technique.

$nick = mysql_real_escape_string($_POST['nick']);
$pass = mysql_real_escape_string($_POST['pass']);
$query = "select * from reg_users where username='".$nick."' and pass='".$pass."'";
$q = mysql_query($query,$con) or die(mysql_query());
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top