Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 25th, 2006, 03:29 PM
Registered User
 
Join Date: Jan 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pass an SQL row using hyperlink

I have an assignment where the "Edit" page is accessed by clicking on the row ID for a given record. I'm not supposed to use querystring but use request.form. Querystring isn't working either. My form is POST method not GET method. The database is Access (users.mdb)

Form:
<form action="findString-8.asp?" method="post">
    <textarea name="qstr" rows=1 cols=20></textarea>
    <input type="submit" name="action" value="Find">
</form>
<form action ="formActions.asp?" method="post">
    <input type="submit" name="action" value="Add New Record">
    <input type="submit" name="action" value="Display All">
</form>
------------------------------------------------------------------
There's an array returned from GetRows()
<%for n = 0 to UBound(MyData,2)
Id = MyData(0,n)
firstname = strName(MyData(1,n))
lastname = strName(MyData(2,n))
phone = convertPhone(MyData(3,n))
city = strCity(MyData(4,n))
%>
Part of the table that displays all users
<tr bgcolor=ffffff>

<td><a href="edit.asp"?Id=<%=Id%>><%=Id%></a></td> (problem line)

<td><%=firstname%>&nbsp;<%=lastname%></td>
<td><%=phone%></td>
<td><%=city%></td>
<td><a href="delete.asp"?Id=<%=Id%>>Delete</a></td> (same problem)
</tr>

Even when I use the query string I'm not passing the value. If on edit.asp, I say:
num = request.querystring(Id)

I get an error that the function wants a string.

If I say :
num = request.querystring("Id"),
query = "SELECT firstname from users where id =" & Id, I get the error that there's a missing operator with 'id ='

I believe I can't use querysting because I'm using POST. But I have no idea how to pass one entire row to another page.

Thanks,
ma


 
Old May 25th, 2006, 03:34 PM
Authorized User
 
Join Date: Jun 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to erobb Send a message via Yahoo to erobb
Default

I see a couple of initial simple issues with your code, can you correct these and let me know where we stand?

Change
<form action ="formActions.asp?" method="post">
To
<form action ="formActions.asp" method="post">

Change
<a href="edit.asp"?Id=<%=Id%>><%=Id%>
to
<a href="edit.asp?Id=<%=Id%>"><%=Id%></a>

Earl
www.jhdesigninc.com
 
Old May 25th, 2006, 03:49 PM
Registered User
 
Join Date: Jan 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I posted this while at work so can't get to the files 'til I get home. I'll correct those and let you know where I stand.

thanks

 
Old May 25th, 2006, 05:08 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your forms contain just buttons. If you want to pass the id back from this form in the post, you should add an input field to contain the id.
Code:
<input type='hidden' name='hdnId' value='YOUR_ID_VALUE_HERE'>
Woody Z http://www.learntoprogramnow.com
 
Old May 25th, 2006, 07:49 PM
Registered User
 
Join Date: Jan 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK, I fixed the form syntax and I included the input field with the hidden value. Now the hyperlink value is being passed to the edit.asp page.

So far, so good... whew...thank you

Now my next problem is the SQL syntax, I believe.

I picked up my value on edit.asp with:
IdLink=request(Id)

My query string is:
qstr = "SELECT firstname, lastname, city, phone FROM users WHERE id = " & IdLink & ""

This is the error:
Syntax error (missing operator) in query expression 'id ='.
/asp/Assignment8/dbutils-8.asp, line 37

I want to say the following. Suppose the Idlink = 3:
SELECT firsname, lastname, phone, city from users WHERE id = 3


This is a SQL syntax error isn't it?

Thank you


 
Old May 25th, 2006, 08:15 PM
Authorized User
 
Join Date: Jun 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to erobb Send a message via Yahoo to erobb
Default

OK need little more code. Is Id var the same one as in the code or are you trying to use (note syntax difference):

IdLink=request.form("Id") to get a query string?

Are you trying to convert it from a queryString to a form object?

Let me Know shouldnt be a biggie.

Earl
www.jhdesigninc.com

 
Old May 25th, 2006, 08:47 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It does look like you have a sql error there.
You might want to response.write out the sql statement to make sure it is correct.
If so, please verify for yourself that the field name for your unique
id is actually Id. This could be a problem in some databases, as Id can be a keyword.

Anyway... there are ways to get around this. In some cases I believe you can use square brackets to indicate that you are using the keyword for some other purpose. Or... you could rename that field in the database.

Also, make sure that this field is an integer field, just in case you are trying to use a naumber where a string is needed - but I doubt this is the case.

Have fun.

Woody Z http://www.learntoprogramnow.com
 
Old May 25th, 2006, 10:19 PM
Registered User
 
Join Date: Jan 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This Id field is an autonumber column in an access database. The columns are ID, firstname, lastname, phone, city. The ID field type is Long. I can see the Id value in the url http://localhost/asp/Assignment8/edit.asp?Id=4

This is the query string.
qstr = "SELECT firstname, lastname, city, phone FROM users WHERE ID = " & IdLink

Here's my error:
Syntax error (missing operator) in query expression 'ID ='.
-------------------------------------------------------------
Starts at search.asp

qstr = "select ID, firstname, lastname, phone, city from users"
    GetRecs(qstr)
<form action ="formActions.asp" method="post">
    <input type="hidden" name="hdnId" value="<%=Id%>">
    <input type="submit" name="action" value="Add New Record">
    <input type="submit" name="action" value="Display All">
</form>

<%for n = 0 to UBound(MyData,2)
        Id = MyData(0,n)
        firstname = strName(MyData(1,n))
        lastname = strName(MyData(2,n))
        phone = convertPhone(MyData(3,n))
        city = strCity(MyData(4,n))


    %>
    <tr bgcolor=ffffff>

        <td><a href="edit.asp?Id=<%=Id%>"><%=Id%></a></td>
        <td><%=firstname%>&nbsp;<%=lastname%></td>
        <td><%=phone%></td>
        <td><%=city%></td>
        <td><a href="delete.asp"?Id=<%=Id%>>Delete</a></td>
    </tr>
    <%next 'n%>
----------------------------------------------------
code on edit.asp

IdLink = request(hdnId)

Call OpenDB ("C:\Inetpub\wwwroot\asp\users.mdb", "", "")
    qstr = "SELECT firstname, lastname, city, phone FROM users WHERE ID = " & IdLink
    'Example: SELECT firsname, lastname, phone, city from users WHERE id = 3"

    GetRecs(qstr)


for n=0 to Ubound(MyData,2)
    Id = MyData(0,n)

    firstname = MyData(1,n)
    lastname = MyData(2,n)
    phone = MyData(3,n)
    city=MyData(4,n)


next 'n
     %>

I'm missing something elementary...
Thanks
MaryAnn

 
Old May 25th, 2006, 10:30 PM
Authorized User
 
Join Date: Jun 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to erobb Send a message via Yahoo to erobb
Default

Wood I really think your focusing on db problems when the majority of the project appears sound to me. IMHO it appears its carring variables and not DB problems.


Earl
www.jhdesigninc.com
 
Old May 25th, 2006, 10:36 PM
Authorized User
 
Join Date: Jun 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to erobb Send a message via Yahoo to erobb
Default

Lets simplify.

Change:
IdLink = request(hdnId)
TO
IdLink = request.form("hdnId")

Your request of the form object looks incorrect to me.

Earl
www.jhdesigninc.com









Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding new row, hyperlink and sheet with a button Shaolin1976 Excel VBA 0 May 8th, 2008 09:01 AM
How to pass gridview selected row msbsam ASP.NET 2.0 Basics 1 March 4th, 2008 09:17 AM
Want to pass a row cursor to a function in a query howardb1 Access VBA 0 April 24th, 2006 03:24 PM
Pass TWO NameValuePairs by Datagrid Hyperlink Col asrar ASP.NET 1.0 and 1.1 Professional 4 January 17th, 2006 04:48 PM
How do you make a Data Grid Hyperlink Column pass KarmenC ASP.NET 1.x and 2.0 Application Design 5 January 13th, 2005 11:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.