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
https://forums.phpfreaks.com/topic/15267-ahhhh-help/
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
https://forums.phpfreaks.com/topic/15267-ahhhh-help/#findComment-61780
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
https://forums.phpfreaks.com/topic/15267-ahhhh-help/#findComment-61792
Share on other sites

Archived

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

×
×
  • 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.