Long time since I have been here old friends, but I need your help today I have gotten stuck and need some code help and guidance. I have searched all over Google and I just cant seem to get this right or to work. To make sure we have a clear understanding I will include many details maybe someone can help me wrap this project up quickly (I have been trying to figure this out for days).
I have the following page that displays a Project and the page name is editproject.asp and I want a user to select a file to upload in the form (It is provided on lines 194 thru 200 and this works). Issue on this page is when they click this I want it to pass the ID (This seens easiest way to pass the record ID) on line 190 to upload_file.php.
Code:
<head>
<!-- #INCLUDE FILE="checklogin.asp" -->
<!-- #INCLUDE FILE="common.asp" -->
<title>Projects</title>
</head>
<!-- #INCLUDE FILE="nav.asp" -->
<%
filename = "projects.asp"
filenameaction = "editproject.asp"
keyname = "projects"
tablename = "tblproj"
'delete project
if request.querystring("delete") = 1 then
id = trim(request.querystring("id"))
projrand = trim(request.querystring("projrand"))
set Conn = server.createobject("adodb.connection")
Conn.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath
mySQL = "Delete FROM " & tablename & " where id = " & id & " and projrand = '" & projrand & "';"
conn.execute(mySQL)
closeconn()
response.redirect(filename)
end if
'update project if form is sent.
if request.form("formid") <> "" then
id = request.form("formid")
set Conn = server.createobject("adodb.connection")
Conn.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath
Set rs = Server.CreateObject("ADODB.RecordSet")
mainSQL = "Select * from " & tablename & " where id = " & id & ";"
'response.write mainsql
rs.Open mainSQL, Conn, 1, 3
if isdate(request.form("projdate")) then
'empty checkbox is not passed so set to nothing by default first.
rs("projprivate") = ""
For Each strItem In Request.Form
execute("rs(" & CHR(34) & strItem & CHR(34) & ") = request.form(" & CHR(34) & strItem & CHR(34) & ")")
Next
updated = 1
else
updated = 2
end if
rs.Update
closers()
closeconn()
response.redirect("editproject.asp?id=" & id & "&updated=" & updated & "&time=" & time())
end if
id = request.querystring("id")
showprojlastuser = Request.Cookies("stampedname")
'display project
set Conn = server.createobject("adodb.connection")
Conn.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath
Set rs = Server.CreateObject("ADODB.RecordSet")
strSQL = "Select tblproj.id,tblproj.projname,tblproj.projdate,tblproj.projcontact,tblproj.projAddress,tblproj.projCity,tblproj.projState,tblproj.projZip,tblproj.projPhone,tblproj.projEmail,tblproj.projStyle,tblproj.projLeadTime,tblproj.projdesc,ProjEmpNotes,tblcat.category,tblstatus.status,tblproj.projorder,tblproj.projlastuser,tblproj.projlastdate,tblproj.projprivate,tblproj.projrand from tblproj,tblcat,tblstatus where tblproj.projcategory = tblcat.id AND tblproj.projstatus = tblstatus.id AND tblproj.id = " & id & " order by tblproj.projorder;"
'Response.Write strSQL
'response.end
rs.Open strSQL, conn,1
count = rs.recordcount
if count <> 1 then
closers()
closeconn()
response.redirect(filename)
end if
For fnum = 0 To rs.Fields.Count-1
execute(rs.Fields(fnum).Name & " = rs(" & CHR(34) & rs.Fields(fnum).Name & CHR(34) & ")")
Next
closers()
closeconn()
'private setting checking
if projprivate = "on" and Request.Cookies("stampedname") <> projlastuser then
response.write "<p class='red'>This is a private project, you do not have permission to view it.</p>"
response.end
end if
upd = request.querystring("updated")
select case upd
case "1"
response.write "<p class='red'>updated</p>"
case "2"
response.write "<p class='red'>invalid date</p>"
end select
%>
<form action="editproject.asp" method="post">
<input type="submit" value="update" class="buttons">
<br><br>
<%=tablehead%>
<tr>
<td><strong>name</strong></td>
<td valign="top"><input type="text" name="projname" value="<%= projname %>" size="45" maxlength="100"> </td>
</tr>
<tr>
<td><strong>date</strong></td>
<td valign="top"><input type="text" name="projdate" value="<%= projdate %>" size="12"> </td>
</tr>
<tr>
<td><strong>Contact</strong></td>
<td valign="top"><input type="text" name="projContact" value="<%= projContact %>" size="45" maxlength="100"> </td>
</tr>
<tr>
<td><strong>Address</strong></td>
<td valign="top"><input type="text" name="projAddress" value="<%= projAddress %>" size="45" maxlength="100"> </td>
</tr>
<tr>
<td><strong>City</strong></td>
<td valign="top"><input type="text" name="projCity" value="<%= projCity %>" size="45" maxlength="100"> </td>
</tr>
<tr>
<td><strong>State</strong></td>
<td valign="top"><input type="text" name="projState" value="<%= projState %>" size="45" maxlength="100"> </td>
</tr>
<tr>
<td><strong>Zip</strong></td>
<td valign="top"><input type="text" name="projZip" value="<%= projZip %>" size="45" maxlength="100"> </td>
</tr>
<tr>
<td><strong>Phone</strong></td>
<td valign="top"><input type="text" name="projPhone" value="<%= projPhone %>" size="45" maxlength="100"> </td>
</tr>
<tr>
<td><strong>Email</strong></td>
<td valign="top"><input type="text" name="projEmail" value="<%= projEmail %>" size="45" maxlength="100"> </td>
</tr>
<tr>
<td><strong>Lead Type</strong></td>
<td valign="top"><input type="text" name="projStyle" value="<%= projStyle %>" size="45" maxlength="100"> </td>
</tr>
<tr>
<td><strong>Lead Time</strong></td>
<td valign="top"><input type="text" name="projLeadTime" value="<%= projLeadTime %>" size="45" maxlength="100"> </td>
</tr>
<tr>
<td valign="top"><strong>description</strong></td>
<td valign="top"><textarea cols="45" rows="4" name="projdesc" class="formfont"><%= projdesc %></textarea> </td>
</tr>
<tr>
<td valign="top"><strong>Employee Notes</strong></td>
<td valign="top"><textarea cols="45" rows="4" name="projEmpNotes" class="formfont"><%= projEmpNotes %></textarea> </td>
</tr>
<tr>
<td title="category"><strong>category</strong></td>
<td valign="top">
<select name="projcategory">
<%call makecombo(category,"tblcat","category")%>
</select>
</td>
</tr>
<tr>
<td title="status"><strong>status</strong></td>
<td valign="top">
<select name="projstatus">
<%call makecombo(status,"tblstatus","status")%>
</select>
</td>
</tr>
<%
If Session("Rights") = "1" THEN
%>
<tr>
<td title="optional sort order critera"><strong>sort</strong></td>
<td valign="top" title="optional sort order critera"><input type="text" name="projorder" value="<%= projorder %>" size="3"> </td>
</tr>
<tr>
<td title="only last user can view and edit"><strong>private</strong></td>
<td valign="top" title="only last user can view and edit"><%=yesno(projprivate,"projprivate")%> </td>
</tr>
<%else%>
<%
end if
%>
<tr>
<td title="date record last updated"><strong>last changed</strong></td>
<td valign="top" title="date record last updated"><%= projlastdate %> </td>
</tr>
<tr>
<td title="last user who updated the project"><strong>last user</strong></td>
<td valign="top" title="last user who updated the project"><%= projlastuser %> </td>
</tr>
</table>
<input type="hidden" name="projlastdate" value="<%=now()%>">
<input type="hidden" name="projlastuser" value="<%=showprojlastuser%>">
<input type="hidden" name="projrand" value="<%=randgen()%>">
<input type="hidden" name="formid" value="<%=id%>">
<input type="submit" value="update" class="buttons">
</form>
<br />
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="Submit" value="Upload" />
</form>
<%
If Session("Rights") = "1" THEN
%>
<p><a href="editproject.asp?delete=1&id=<%=id%>&projrand=<%=projrand%>" onclick="return confirm('Are you sure you want to delete?')" class='red'>delete the project</a></p>
<%
Else
End if
%>
Now we have arrived at Upload_file.php which is mainly to upload the file currently to a directory (THis is only way I could get this to work) but I want it to write the file name with hyperlink path http://fencemstersunlimited.com/uplo...older/FILENAME to the record ID we passed from the previous page editproject.asp. The database name is projectdb.mdb stored in /fpdb/project.mdb and the table name is tblproj and the field is projestimate. After all this is done instead of how it currently just display the file was uploaded I want to redirect back to editproject.asp and open the record back up refreshed with the new data and dispaly "Filename uploaded Successfully" in Red so that you know it was a success instead of the file data.
Here is the code for the Upload_file.php
Code:
<?php
if ((($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("../upload/uploadfolder/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../upload/uploadfolder/" . $_FILES["file"]["name"]);
echo "Stored in: " . "../upload/uploadfolder/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
Thank You in advance for any help with the code provided.