Jump to content

Archived

This topic is now archived and is closed to further replies.

dnienhaus

Ahhhh Help!

Recommended Posts

I am trying to validate links before the print on a page. My problem is I am using a variable in the link itself and it does not parse until runtime right? So when my checkfile.php is called to check if the link exists it always says no because it is seeing "http://intranet/engineering/drawings/{$PARTNUMBER}.pdf" instead of the link with the partnumber thats called. I need to know if there is a way to have the link umm get the part number before it validates it. Anybody have a clue?

search.php


[code]<?php
$username="root";
$password="";
$database="engineering";


mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

if(!empty($_POST['search']))
{
echo '<h1>test</h1>';
$query="SELECT * FROM Assembly WHERE PARTNUMBER LIKE '%" . $_POST['search'] . "%'";
$result=mysql_query($query) or die(mysql_error());

if($result != false)
{
echo "Here are the results:<br><br>";
echo "<table width=90% align=center border=1><tr>
<td align=center bgcolor=#00FFFF><b>Creation Date</b></td>
<td align=center bgcolor=#00FFFF><b>Creator</b></td>
<td align=center bgcolor=#00FFFF><b>Nomenclature</b></td>
<td align=center bgcolor=#00FFFF><b>OBID</b></td>
<td align=center bgcolor=#00FFFF><b>Part Number</b></td>
<td align=center bgcolor=#00FFFF><b>Part Drawing</b></td>
</tr>";

while ($r = mysql_fetch_array($result)) { // Begin while
$CREATIONDATE = $r["CREATIONDATE"];
$CREATOR = $r["CREATOR"];
$NOMENCLATURE = $r["NOMENCLATURE"];
$OBID = $r["OBID"];
$PARTNUMBER = $r["PARTNUMBER"];
$PARTNUMBER = str_replace('"','',$PARTNUMBER);

//////////////////////////////////////////////////////////////////////////////////////////////////////

$url = "http://intranet/engineering/drawings/$PARTNUMBER.pdf";

include ('checkfile.php');

//////////////////////////////////////////////////////////////////////////////////////////////////////

echo "<tr>
<td><center>$CREATIONDATE</center></td>
<td><center>$CREATOR</center></td>
<td><center>$NOMENCLATURE</center></td>
<td><center>$OBID</center></td>
<td><center><b>$PARTNUMBER</b></center></td>
<td><center>$url</center></td></tr><br><br><hr>";
} // end while
echo "</table>";
} else { echo "problems...."; }
} else {
echo "Search string is empty. <br> Go back and type a string to search";
}

?>[/code]


checkfile.php

[code]<?php

$link = $url;

echo "Checking: $link<br><br>\n"; flush();

$fp = @fopen($link, "r");
if (!$fp) { echo "No File"; }
else { fclose($fp); echo "Yay it's there!"; }

?>[/code]

Share this post


Link to post
Share on other sites
You only posted this an hour ago, give us some time to see it....

You don't need the curly braces in this line:
[code]<?PHP $url = "http://intranet/engineering/drawings/{$PARTNUMBER}.pdf"; ?>[/code]
remove them.

Ken

Share this post


Link to post
Share on other sites
Is the file you're looking for on the same system as the running script? If so, do not use "http://" in the filespec, just use the local path.

Ken

Share this post


Link to post
Share on other sites
the problem is not with the file its with using the $PARTNUMBER variable in the url and i can't figure out how to get it to read whats stored in the variable instead of the plaintext $PARTNUMBER.

Share this post


Link to post
Share on other sites
This code:
[code]<?php $url = "http://intranet/engineering/drawings/$PARTNUMBER.pdf"; ?>[/code]
or
[code]<?php $url = 'http://intranet/engineering/drawings/' . $PARTNUMBER '.pdf'; ?>[/code]
Will put the value of $PARTNUMBER into the string $url.  Echo the string $url after the assignment.

Ken

Share this post


Link to post
Share on other sites
Please post your current code again.

Ken

Share this post


Link to post
Share on other sites
Updated code:


search.php

[code]<?php
$username="root";
$password="";
$database="engineering";


mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

if(!empty($_POST['search']))
{
echo '<h1>test</h1>';
$query="SELECT * FROM Assembly WHERE PARTNUMBER LIKE '%" . $_POST['search'] . "%'";
$result=mysql_query($query) or die(mysql_error());

if($result != false)
{
echo "Here are the results:<br><br>";
echo "<table width=90% align=center border=1><tr>
<td align=center bgcolor=#00FFFF><b>Creation Date</b></td>
<td align=center bgcolor=#00FFFF><b>Creator</b></td>
<td align=center bgcolor=#00FFFF><b>Nomenclature</b></td>
<td align=center bgcolor=#00FFFF><b>OBID</b></td>
<td align=center bgcolor=#00FFFF><b>Part Number</b></td>
<td align=center bgcolor=#00FFFF><b>Part Drawing</b></td>
</tr>";

while ($r = mysql_fetch_array($result)) { // Begin while
$CREATIONDATE = $r["CREATIONDATE"];
$CREATOR = $r["CREATOR"];
$NOMENCLATURE = $r["NOMENCLATURE"];
$OBID = $r["OBID"];
$PARTNUMBER = $r["PARTNUMBER"];
$PARTNUMBER = str_replace('"','',$PARTNUMBER);

$url = 'http://intranet/engineering/drawings/' . $PARTNUMBER '.pdf';
echo "$url";
include ('checkfile.php');

echo "<tr>
<td><center>$CREATIONDATE</center></td>
<td><center>$CREATOR</center></td>
<td><center>$NOMENCLATURE</center></td>
<td><center>$OBID</center></td>
<td><center><b>$PARTNUMBER</b></center></td>
<td><center>$url</center></td></tr><br><br><hr>";
} // end while
echo "</table>";
} else { echo "problems...."; }
} else {
echo "Search string is empty. <br> Go back and type a string to search";
}

?>[/code]


checkfile.php

[code]<?php

$link = $url;

echo "Checking: $link<br><br>\n"; flush();

$fp = @fopen($link, "r");
if (!$fp) { echo "No File"; }
else { fclose($fp); echo "Yay it's there!"; }

?>[/code]

Share this post


Link to post
Share on other sites
$url = 'http://intranet/engineering/drawings/' . $PARTNUMBER '.pdf';

i think it should be

$url = 'http://intranet/engineering/drawings/' . $PARTNUMBER . '.pdf';

or it may not matter. but you can try.

Share this post


Link to post
Share on other sites
got rid of the blank page but url still doesn't validate. and it does exist. i have the same problem still nothing has changed. bummer.

Share this post


Link to post
Share on other sites
When you say "blank page", do you mean that no text is showing on your page?

Make sure all errors are being shown by putting
[code]<?php error_reporting(E_ALL); ?>[/code]
at the start of your code.

Ken

Share this post


Link to post
Share on other sites
use file_exists("~" . $PARTNUMBER . ".php") or die("no such file")  (replaceing ~ with that url that i was to lazy to type)...

Share this post


Link to post
Share on other sites
if i copy and paste the url it has it open the file so it does exist just won't say so. returns...

test

Here are the results:

no such file

Share this post


Link to post
Share on other sites
Are you allowed to use "http://" in the filespec. Check to make sure that the ini directive allow_url_fopen is set to "1". Also, remove the "@" from infront of the fopen, that could be surpressing a critical error message.

Ken

Share this post


Link to post
Share on other sites
test
Here are the results:

Checking: http://intranet/engineering/drawings/024T-G4203.pdf

No File http://intranet/engineering/drawings/024T-G4203.pdf

when i copy and paste that the file opens so ahhh! No errors either.

Share this post


Link to post
Share on other sites
Remember, since PHP runs on the server it may not have access to the same files/domains you have when running from the browser.

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.