Proof read my ASP script please?

Discussion in 'Web Design and Development' started by ghostchild, Aug 10, 2009.

  1. ghostchild macrumors 6502

    ghostchild

    Joined:
    Jun 17, 2007
    #1
    Hey all so I just wrote one of my first ASP scripts, but I found a problem with it, I just am not very sure how to fix it. The textarea below the "Brand" textarea to be specific. Lets say I type something in it then hit enter and type another thing when I submit the results only show the first item I enter and not the second.... am i being clear?

    Here's the code...
    PHP:
    <% 

    ink_type            request("ink_type") : if ink_type "" then ink_type "Toner" 

    brand                    request("brand") & " " 

    product_list    request("product_list")  



    'response.write product_list 

    '
    response.end 

    if product_list <> "" then 



        toner_keywords    
    request("toner_keywords")  

        
    ink_keywords    request("ink_keywords")  

        
    fax_keywords    request("fax_keywords")  

        
    drum_keywords    request("drum_keywords")  
         
        
    toners_keywords    request("toners_keywords")  

        
    inks_keywords    request("inks_keywords")  

        
    faxes_keywords    request("faxes_keywords")  

        
    drums_keywords    request("drums_keywords")  

            
    select case ink_type 

                
    case "Toner":        arrKeywords split(request("toner_keywords"), vbcrlf

                case 
    "Ink":            arrKeywords split(request("ink_keywords"), vbcrlf

                case 
    "Fax":         arrKeywords split(request("fax_keywords"), vbcrlf

                case 
    "Drum":         arrKeywords split(request("drum_keywords"), vbcrlf

                case 
    "Toners":        arrKeywords split(request("toners_keywords"), vbcrlf

                case 
    "Inks":        arrKeywords split(request("inks_keywords"), vbcrlf

                case 
    "Faxes":         arrKeywords split(request("faxes_keywords"), vbcrlf

                case 
    "Drums":         arrKeywords split(request("drums_keywords"), vbcrlf

            
    end select 



    if instr(1,product_list,vbcrlf) = 0 then product_list product_list vbcrlf 



        
    if instr(1,product_list,vbcrlfthen 'multiple 

            arrProduct_List = split(product_list, vbcrlf) 



            for m = 0 to ubound(arrProduct_List)-1 



                for i = 0 to ubound(arrKeywords) 

                    if trim(brand) <> "" then  

                        str1 =  str1 & brand & arrProduct_List(m) & " " & arrKeywords(i) & vbcrlf 

                    else 



                    end if 

                    if trim(arrProduct_List(m)) <> "" then str2 = str2 & arrProduct_List(m) & " " & arrKeywords(i) & vbcrlf   

                next 

            next 



        else ' 
    single  



            
    'for i = 0 to ubound(arrProduct_List) 

            '        
    if trim(arrProduct_List(i)) <> "" then str2 str2 arrProduct_List(i) & " " arrKeywords(i) & "<br>"     

            'next 

        end if 



    else 

        '
    strConnection "driver={MySQL};server=localhost;uid=toner;pwd=toner;database=monster_toner_db;option=" 

        'Set Conn = Server.CreateObject("ADODB.Connection")  

        '
    Set RS Server.CreateObject("ADODB.Recordset")  

        
    'Conn.Open strConnection  



        toner_keywords = "toner"",""toner cartridge"",""printer cartridge"",""laser toner"",""cartridge"",""printer toner"

        ink_keywords = "cartridge"",""ink"",""ink cartridge"",""inkjet"",""inkjet cartridge"",""printer cartridge"",""printer ink"

        fax_keywords = "fax film"",""fax ribbon"",""fax ribbon cartridge"",""ribbon"",""film"

        drum_keywords = "drum printer"",""drum cartridge"",""drum unit" 

        toners_keywords = "toners"",""toner cartridges"",""printer cartridges"",""laser toners"",""cartridges"",""printer toners" 

        inks_keywords = "cartridges"",""inks"",""ink cartridges"",""inkjets"",""inkjet cartridges"",""printer cartridges"",""printer inks "

        faxes_keywords = "fax films"",""fax ribbons"",""fax ribbon cartridges"",""ribbons"",""films"

        drums_keywords = "drum printers"",""drum cartridges"",""drum units" 



    end if 



    response.write "<textarea cols=100% rows=20>" & str2 & str1 & "</textarea>" 



    %> 

    <basefont face="arial" size=1> 

    <form action="" method=post> 

    <table cellspacing=10 cellpadding=10><tr><td valign=top> 

    <br> 

    <input type=radio value="Toner" <%if ink_type = "Toner" then response.write "checked" %> name="ink_type"><b>1. Toner</b>   

    <input type=radio value="Ink" <%if ink_type = "Ink" then response.write "checked" %> name="ink_type"><b>2. Ink</b>    

    <input type=radio value="Fax" <%if ink_type = "Fax" then response.write "checked" %> name="ink_type"><b>3. Fax</b>   

    <input type=radio value="Drum" <%if ink_type = "Drum" then response.write "checked" %> name="ink_type"><b>4. Drum</b> 
    <br> 
    <input type=radio value="Toners" <%if ink_type = "Toners" then response.write "checked" %> name="ink_type"><b>5. Toners</b>   

    <input type=radio value="Inks" <%if ink_type = "Inks" then response.write "checked" %> name="ink_type"><b>6. Inks</b>    

    <input type=radio value="Faxes" <%if ink_type = "Faxes" then response.write "checked" %> name="ink_type"><b>7. Faxes</b>   

    <input type=radio value="Drums" <%if ink_type = "Drums" then response.write "checked" %> name="ink_type"><b>8. Drums</b> 
    <br><br> 

    Brand: <input type=text value="<%=trim(brand)%>" name="brand" size=20 > 

    <br> 

    <textarea name="product_list" cols=50 rows=10><%=product_list%></textarea><br> 

    <input type=submit value=submit> 

    </td><td valign=top> 

    <br> <br> 

    <b>1. Toner keywords:</b><br> <textarea name="toner_keywords" cols=50 rows=7><%=replace(toner_keywords,""",""", vbcrlf)%></textarea><br><br> 

    <b>2. Ink keywords: </b><br><textarea name="ink_keywords" cols=50 rows=7><%=replace(ink_keywords,""",""", vbcrlf)%></textarea><br><br> 

    <b>3. Fax keywords: </b><br><textarea name="fax_keywords" cols=50 rows=7><%=replace(fax_keywords,""",""", vbcrlf)%></textarea><br><br> 

    <b>4. Drum keywords: </b><br><textarea name="drum_keywords" cols=50 rows=7><%=replace(drum_keywords,""",""", vbcrlf)%></textarea><br><br> 

    <b>5. Toners keywords:</b><br> <textarea name="toners_keywords" cols=50 rows=7><%=replace(toners_keywords,""",""", vbcrlf)%></textarea><br><br> 

    <b>6. Inks keywords: </b><br><textarea name="inks_keywords" cols=50 rows=7><%=replace(inks_keywords,""",""", vbcrlf)%></textarea><br><br> 

    <b>7. Faxes keywords: </b><br><textarea name="faxes_keywords" cols=50 rows=7><%=replace(faxes_keywords,""",""", vbcrlf)%></textarea><br><br> 

    <b>8. Drums keywords: </b><br><textarea name="drums_keywords" cols=50 rows=7><%=replace(drums_keywords,""",""", vbcrlf)%></textarea><br><br> 

    </td></tr> 

    </table> 

    </form>  
    <body>
    </body>
    </html>
    Thanks,
    John
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    I've never written ASP, but based on a quick search try,
    PHP:
    product_list Request.Form("product_list")
     
  3. ghostchild thread starter macrumors 6502

    ghostchild

    Joined:
    Jun 17, 2007
    #3
    hmm.. doesn't seem to work.
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    To ensure I interpreted the question correctly; It sounds like when the textarea in question has more than one line of text in it, only the first line of text is stored in the variable. So if you type in,
    Code:
    This is my first line.
    This is my second line.
    The product_list variable would only be equal to "This is my first line."
     
  5. ghostchild thread starter macrumors 6502

    ghostchild

    Joined:
    Jun 17, 2007
    #5
    yes, that is correct, now if I enter an extra enter space the first two lines will show and not the third so the last one always ca not be displayed for some reason.

    Code:
    This is my first line.
    This is my second line.
    enter
    
    this is the only way to get the second line to show right now.
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    Have you check if the variable is set right at this line?
    Code:
    'response.write product_list
    It's currently commented out (I think that's what the ' does). I don't have a way to debug the code so it makes it hard. If it's correct at that point, then the issue is likely in one of the for loops where it may be ending too soon.
     
  7. ghostchild thread starter macrumors 6502

    ghostchild

    Joined:
    Jun 17, 2007
    #7
    hmm... it seems correct. I've triple checked it... :confused::confused:
     
  8. cr2sh macrumors 68030

    cr2sh

    Joined:
    May 28, 2002
    Location:
    downtown
    #8
    I'm not real good with ASP but I have a couple questions. First, is the trim in your input's value field necessary.. have you tried taking it out? Second, is the test box is setup to be multiline?

     
  9. Cerebrus' Maw macrumors 6502

    Joined:
    Mar 9, 2008
    Location:
    Brisbane, Australia
    #9
    Is there a way to dump a variable to the screen within ASP? (As you can tell => Not an asp guy....)

    In PHP, you have the var_dump($var); method, which tells you the variable type and its value.

    If I find a variable is not what I expected it to be (different value, odd value, or worse, no value at all), I'll just dump it where I first think it gets intialized.

    So in this case, where you have

    Code:
    product_list    = request("product_list")
    
    I would dump it at the next line. If it's as expected, then at least you know the problem is in your script, and you can dump the product_list after every operation you do to it. Once you find dump where the problem starts happening, you know that the last operation you did to the variable is where it's stuffing up.

    If your first dump is wrong, then you know its not being passed correctly to your script. (Does IIS have someting like magic_quotes_on???)
     
  10. ghostchild thread starter macrumors 6502

    ghostchild

    Joined:
    Jun 17, 2007
    #10
    How do you make it multi-line?
     
  11. memco macrumors 6502

    Joined:
    May 1, 2008
    #11
    This line is the culprit I think:

    PHP:
    for 0 to ubound(arrProduct_List)-
    Change it to:
    PHP:
    for 0 to ubound(arrProduct_List)
    Give that a run and let us know how it fares.
     
  12. ghostchild thread starter macrumors 6502

    ghostchild

    Joined:
    Jun 17, 2007
    #12
    Nice! it works, now it just makes me curious as to why that -1 was there....
     

Share This Page