Jump to content

Ahhhh Help!


dnienhaus

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]
Link to comment
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
Link to comment
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
Link to comment
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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.