PDA

View Full Version : To get Users POST by ID in Diferent table in ASP MySQL, PLEASE HELP.


mimitaro
03-17-2009, 08:52 PM
I am a beginner please some1 Help me please.

My requirement is to display users post comments (to the table - userpoststbl) based on the ID of picture selected (pictures are in the table of "viewdatatbl"). Eg: like youtube. Users comments on a particular video only will be displayed.

I have two tables. One is "viewdatatbl (thats the table that holds the picture)" and a table named "userpoststbl - where users will post data that will enter to this table)". Both tables has IDS.



<a href="comments.asp?id=<%=rs("id")%>"><p align="center">more</a>
When click that this is the page that will display the picture and the users input form to post based on picture selection.


>>>comments.asp code:------------------

<%
Dim strProvider

Dim rs
Set rs = Server.CreateObject("ADODB.recordset")

strProvider = "Driver={MySQL ODBC 5.1 Driver}; Server=localhost;Database=viewdatadb;UID=root;PWD=123456"
set dbConn = server.createObject("ADODB.connection")
dbConn.Open(strProvider)

'This is calling from the viewdata.asp the images and the rest of the db values based on the id.
strIDNum=Request("id")
strQuery="select * FROM viewdatatbl WHERE id = " &strIDNum
rs.Open strQuery, strProvider

%>

</body><a href="viwdata.asp">&lt;&lt;Back to View<body></a></p>
<table border="0" width="489" cellspacing="3" id="table1" height="195" cellpadding="3">
<tr>
<td bgcolor="#FFFFFF" height="38">
<p align="center"><b>View Data Image Info</b></td>
</tr>
<tr>

<td align="center"><img src="<%=rs("image")%>" height="300" ><p align="center">Name: <%=rs("name")%></td>

</tr>
</table>

<p>--------------------------------------------------------------------------------------------------------</p>

<p align="left"><span style="font-family:Tahoma; font-weight:700">
<font size="4">User post data</font></span><br>


<%
Dim vusername
vusername = Request.form("inpusername")

Dim vuseremail
vuseremail = Request.form("inpuseremail")

Dim vusercomment
vusercomment = Request.form("inpusercomment")

Dim varviewdatatblid
varviewdatatblid = Request.form("viewdatatblid")


Dim rsUser
Set rsUser = Server.CreateObject("ADODB.Recordset")
rsUser.Open "userpoststbl", strProvider, 2, 2

if not trim(vusername) = "" then
rsUser.AddNew

rsUser("username") = vusername
rsUser("useremail") = vuseremail
rsUser("usercomment") = vusercomment
rsUser("storeviewdatatblid") = varviewdatatblid

rsUser.Update

rsUser.Close
end if
Set rsUser = Nothing


%>
<table border="0" width="329" cellspacing="3" id="table1" height="195" cellpadding="3">
<tr>
<td height="27" colspan="2"><b>User Input comments (Based on ID)</b></td>
</tr>
<tr>
<td height="27" width="87">Your Name&nbsp; </td>
<td height="27" width="221">

<form method="POST" action="comments.asp">
<input type="hidden" name="viewdatatblid" value="<%=rs("id")%>">
<input name="inpusername" size="30" >

</td>
</tr>
<tr>
<td height="27" width="87">Email</td>
<td height="27" width="221"> <input name="inpuseremail" size="30" ></td>
</tr>
<tr>
<td height="27" width="87">Comments</td>
<td height="27" width="221">
<textarea name="inpusercomment" cols="25" rows="5" ></textarea></td>
</tr>
<tr>
<td height="27" width="87"><font size="2">viewdatatbl id</font></td>
<td height="27" width="221"><%=rs("id")%></td>
</tr>
<tr>
<td height="27" width="87">&nbsp;</td>
<td height="27" width="221">
<font color="#6599FF">
<input type="submit" value="Submit"></font></td>
</tr>
</table>
</form>


<!-- {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{User Posts }}}}}}}}}}}}}}}}}}}}}}}}}}}-->

<%
rs.Close
Set rs = Nothing
Set connStr = Nothing
%>


<br>
<br>
<br>
<br>

<!-- Display User Inputs Based on ID -->
<iframe scrolling="yes" width="912" src="userpostdatabyIDpicturepost.asp" frameborder="0" height="302"></iframe>
<!-- Display User Inputs Based on ID -->



When I try to add the form data, with the hidden form value <input type=hidden name="viewdatatblid" value="<%=rs("id")%>"> I get this error


Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[MySQL][ODBC 5.1 Driver][mysqld-5.0.41-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
/postcommentsbasedonID/comments.asp, line 14


Line no 14 is: rs.Open strQuery, strProvider

Display picture based on ID is working, my problem is I am trying to snatch the ID <input type=hidden name="viewdatatblid" value="<%=rs("id")%>"> and write to the table " userpoststbl "the value taken (rightly) but i need help to write to the table "userpoststbl" the id of "viewdatatbl". It gives error as above with rs.Open strQuery, strProvider

Please help me with this page to sort writing that id to the table please. I am a beginner so any mistakes please excuse me.

Thanking you.

brazenskies
03-17-2009, 09:21 PM
the problem lies here...


strQuery="select * FROM viewdatatbl WHERE id = " &strIDNum


response.write("strQuery") and see what gets printed out.

I'm guessing it's going to look like....


select * FROM viewdatatbl WHERE id =


If so, try changing...


strIDNum=Request("id")


to...


strIDNum=Request.querystring("id")


Be careful though, thats wide open to sql injection

mimitaro
03-17-2009, 09:34 PM
O thank you for the speedy reply. Infact I am so sorry I had to upload a more working code. I tried yours the same error. My problem is with snatching the ID. PLease help me.


the problem lies here...


strQuery="select * FROM viewdatatbl WHERE id = " &strIDNum


response.write("strQuery") and see what gets printed out.

I'm guessing it's going to look like....


select * FROM viewdatatbl WHERE id =


If so, try changing...


strIDNum=Request("id")


to...


strIDNum=Request.querystring("id")


Be careful though, thats wide open to sql injection

brazenskies
03-17-2009, 09:38 PM
what happened when you wrote strQuery to the screen?

I don't quite understand. are you getting the id value from the url or from the hidden field?

mimitaro
03-17-2009, 09:45 PM
Yes I am getting the image and the ID displyed fine. Only thing

Dim varviewdatatblid
varviewdatatblid = Request.form("viewdatatblid")

rsUser("storeviewdatatblid") = varviewdatatblid

rsUser.Update

rsUser.Close
end if
Set rsUser = Nothing

there I am tryng to write the ID hidden value to that table thats causing trouble

<form method="POST" action="comments.asp">
<input type="hidden" name="viewdatatblid" value="<%=rs("id")%>">

when say with record set to get id

<input type="hidden" name="viewdatatblid" value="<%=rsUser("id")%>"> it displys only One ID. the correct I have added. The issue is with writing the ID to table.

brazenskies
03-17-2009, 09:52 PM
sorry, I misread the problem originally.

mimitaro
03-17-2009, 09:57 PM
This part is sorted. Thanks.