[Tutor] List problem

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Wed, 2 May 2001 18:12:02 -0700 (PDT)


On Wed, 2 May 2001, Sharriff Aina wrote:

> ### code start ###
> 
>  fields = allrows[0]
>  if fields[3] == usernamevalue and fields[4] == passwordvalue :
> .... print block1, # blocks of HTML code
> .... print fields[18],
> .... print block2
> .... print usernamevalue,
>  ....print block3
> elif fields[3] != usernamevalue and fields[4] != passwordvalue :
>  ....print errorpage
> 
> #### code end ####

It looks like this is code that you typed at the interpreter.  Is this the
same code you're using within the CGI script?



> the problem is, when correct values are entered in the form everything
> works fine as soon as one enters a false password or false username I get
> this error
> 
> "Traceback (most recent call last):
>   File "cgi-bin/login.cgi", line 119, in ?
>     fields = allrows[0]
> IndexError: list index out of range

I'm guessing that if they enter in a bad password or username, that the
allrows list is empty.  Can you show us the code that grabs allrows?  It
looks like you're doing a "SELECT" sql command to grab all the columns.  
However, if it can't find a person within the database, it should probably
return no rows at all.



> If its out of range why does it work corretly when the data filled in is
> correct? the mid boggling  X-files part of it is that it works when I
> simulate this code in the Python console!!

We'll need to see how you're assigning allrows. If the username/password's
misspelled, it looks like it won't be able to fetch any rows.  You code
probably needs to take care of this case; it can't immediately fetch the
first element of allrows.

Hope this helps!