Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Complete Newbie

Status
Not open for further replies.

chinedu

Technical User
Mar 7, 2002
241
US
Hello all,
I am completely 100% php newbie.

I have been working with asp for a while now and have been presented with the challenge of viewing a pdf with php.

I have done something similar with asp which is this:

Code:
<%


	' Create ADO Connection
	Set Conn = Server.CreateObject("ADODB.Connection")
	Conn.Open "Provider=SQLOLEDB.1;Password=sonn1e;Persist Security Info=True;User ID=sam.okeh; " & _
                          "Initial Catalog=Traf;Data Source=pw2 "
    Response.ContentType = "application/pdf"
	' Create Recordset
	Set RecSet = Server.CreateObject("ADODB.Recordset")
	RecSet.Open "select fileData from TrafficCountsFiles where siteCode ='" & Request("siteCode")& "' ", Conn, 2, 3

	If Not RecSet.EOF Then
     ' set the ContentType property
      Response.Addheader "Content-Disposition", "inline; filename=file.pdf"
     ' send the binary data to the webbrowser
      Response.BinaryWrite (RecSet("fileData"))
	End If

	RecSet.Close
	Set RecSet = Nothing

	Conn.Close
	Set Conn = Nothing

Above code allows me to click on a pdf file and open on a browser to view contents.

Well, since our php guy is on a maternity leave (his wife had a baby) for 3 weeks and we needed to get this done,
I have been trying to re-write it in php.
So far, I am getting errors that I really don't know how to resolve.


I was wondering if someone could be kind enough to help me resolve this.

Here is my table structure.
Table name: Access database
ID autonumber
sitecode text
filesize number
filedata OLE Object (or BLOB)
contentType text
filename text

I just keep getting File does not exist.
I know the reason is because I am using mySQL syntax but my database is not mySQL.

Here is the php version I have been working on.
I truly appreciate any help.

Code:
<?php
// DB connection here.
$conn=odbc_connect('counts','','');

$sql = "SELECT FileData FROM trafficCountsFiles,fctrafic where fctrafic.site_code = trafficcountsFiles.sitecode and siteCode = '".$_GET["siteCode"]."'"; $rs=odbc_exec($conn,$sql);

if (!$rs)
{
 exit("Error in SQL");
}
if (($rs) == 1)

{

$fileType = mysql_result($result, 0, "contentType");
$fileContent = mysql_result($result, 0, "filedata");
header("Content-Type: $fileType");
header("Content-Length: " . strlen($filedata));
header("Content-Disposition: inline; filename=file.pdf;");

echo $fileContent;

}

else

{

echo "Record doesn't exist.";

}

?>
[code]
 
You are still not answering my questions.
Am I not being clear?

What I would like to know and this is going to help me understand what is going on and that is, when you said it exactly macthes my output, do you mean to say that I did it correctly?

If no, what is the proper syntax?
If yes, why am I not seeing real values there instead of [STITE_CODE] as the value.
Why not something like:

Site Code
23333

instead of
site Code
[SITE_CODE]

Why are the rest not like this?

Maybe you have been trying to explain them; I am just not getting it.

 
You're just not getting it.

You're seeing "[SITE_CODE]" there instead of real values because the links produced by your code contain "[SITE_CODE]" instead of real values:

chinedu said:
<td class="name">Site Code </td>
<td class="name">Distance </td>
<td class="name">&nbsp;</td>


<td class="value">[SITE_CODE]</td>
<td class="value">[DISTANCE]</td>
<td class="name" width="10%" align="center" valign="top"><font size="-1"><a href="#" onClick="window.open('[red][SITE_CODE][/red]','','width=500,height=200,scollbars,resizable=yes')">Study Info</a></font></td>

Whatever values your first script produces in those links are the values that, when clicked, will be passed to the next script.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Ok, I see; now I got it.
Thanks for being very patient.

Do you have any idea how I can fix it then?

What I want is to get the value from the form page and pass that to the next page.

Any help would be greatly appreciated.
 
Your code which provides those links must actually insert values in the place where you are currently using "[SITE_CODE]".

I assume you have a database in which these values are available. Fetch the values from there and loop through them, providing links with real data.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top