request.form syntax problems

Results 1 to 6 of 6

Thread: request.form syntax problems

  1. #1
    Join Date
    Dec 1969
    Posts
    17

    Default request.form syntax problems

    I am having trouble getting the correct syntax on this query. I am a beginner at ASP and SQL. The query should select records where the "Name" field is the same as the data posted from the previous web page&#039s form. E.G., the data is being sent like "/reports/home.asp?Name=McDonalds"<BR><BR>The query in the &#039home.asp&#039 page currently looks like this, but I can not figure out what I am doing wrong. Any help would be greatly appreciated:<BR><BR>&#060;%<BR>rs.Open "SELECT Name, WebsiteAddress, Telephone, TickerSymbol FROM CORPORATESUMMARY WHERE Name = request.form(Name)", conn<BR>%&#062;

  2. #2
    Join Date
    Dec 1969
    Posts
    109

    Default RE: request.form syntax problems

    VBScript, unfortunately, does not do variable interpretation<BR>within double quotation marks (like PerlScript does). So,<BR>your sql statement is telling the database to look for a<BR>name that equals, literally, request.form(Name).<BR><BR>rs.Open "SELECT Name, WebsiteAddress, Telephone, TickerSymbol FROM CORPORATESUMMARY WHERE Name = request.form(Name)", conn<BR><BR>The proper syntax is:<BR><BR>rs.Open "SELECT Name, WebsiteAddress, Telephone, TickerSymbol FROM CORPORATESUMMARY WHERE Name = &#039" & request.form(Name) & "&#039", conn<BR><BR>request.form(Name) is evaluated and appended to the end of the<BR>string. Note also that whatever the value of request.form(Name)<BR>is needs to be included in single quotation marks for the sql statement to be valid (because Name is a string).<BR><BR><BR>Oliver

  3. #3
    Nathan Pond Guest

    Default RE: request.form syntax problems

    use Request.QueryString("Name")<BR><BR>Request.Form is used when form data is submitted to that ASP page with the POST method. When the data is sent as part of the URL, like in your case, that is the GET method, which uses Request.QueryString. <BR><BR>Hope this helped<BR><BR>Nathan Pond

  4. #4
    Yiftach Guest

    Default RE: request.form syntax problems

    The query should be something like this:<BR>&#060;%<BR>rs.Open "SELECT Name, WebsiteAddress, Telephone, TickerSymbol FROM CORPORATESUMMARY WHERE Name = &#039" & request.form("Name") & "&#039", conn<BR>%&#062;<BR><BR>The difference between this query and the query you showed is that you included the request.form("Name") inside the query so the script processes it as a part of the syntax and not as a variable. And another thing. You said that that the data will come like this: "/reports/home.asp?Name=McDonalds"<BR>In that case instaed of request.form("Name") you should do request.querystring("Name").<BR><BR>Hope it helps, after all I&#039m 14 years old and I started several months ago writing ASP.<BR><BR>Yiftach.


  5. #5
    Join Date
    Dec 1969
    Posts
    17

    Default RE: got it! thanks so much :-)

    I think I have the hang of it now. single quotes and double quotes were mixing me up. Makes C++ look easy! <BR><BR>Thanks again, especially to all you 14-year-olds out there that know so much more than us 18-year-olds.

  6. #6
    Join Date
    Dec 1969
    Posts
    112

    Default RE: request.form syntax problems

    the easy way of doing this would be<BR>assigning request.form to some variable, say<BR>nameP=request.form("name")<BR>and then depending on whether you make that nameP an integer or just a string use this:<BR>for int<BR>SELECT Name, WebsiteAddress, Telephone, TickerSymbol FROM CORPORATESUMMARY WHERE Name = "&nameP&"<BR>or for str<BR>SELECT Name, WebsiteAddress, Telephone, TickerSymbol FROM CORPORATESUMMARY WHERE Name = &#039"&nameP&"&#039

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •