PDA

View Full Version : cache issue ? idk pls help !



miradoro
12-11-2007, 02:12 PM
:confused:

Hi

i have this code that reads a txt file and pop ups a pdf if a part number is associated with it. if a part number is enter and it is not in the txt file a warning shows. my problem is that the warning stays on the page even if you refresh it...is there a way to clear it ?

Heres the code:

<form name="frmSearch" method="post" action="<?php echo $PHP_SELF;?>" onSubmit="return verifyForm(this);">




<td align="center" background="images/Website_13a.jpg">


<input type="hidden" name="action" value="search">

<?
// user sets the file name here.
$data_file = "testdb2.txt";
$prt = $_POST['part_num'];
$dataset = file("testdb2.txt");
$pdfPath = "";
if( $prt != "" && $_POST['action']=="search" )
{
for( $i = 0; $i < count( $dataset ); $i++ ){
// extract the record key and compare
$dataset[$i] = trim( $dataset[$i] );
$record_key = strtok( $dataset[$i], " " );
$record_key = trim( $record_key );
if( strcmp( $record_key, $prt ) == 0 ) {
$stringArray = explode( " ", $dataset[$i], 2 );
$pdfPath = trim( $stringArray[1] );
?>
<script language="JavaScript" type="text/javascript">
window.open('<?echo($pdfPath);?>');
</script>
<?
break;
} // end of if
} // end of for
} // end of outermost if

// if it gets to this point, the record was not found in the file.
?>

<input name="part_num" type="text" id="part_num" size="12"></td>
<td width="32"><input type="image" src="images/Website_14.jpg" name="Submit" value="Search"></td>
<!--displayin error -->

<font color="red" style="font-family:Arial, Helvetica, sans-serif" size="-1">

<?
$error_msg = "";
if( $pdfPath == "" ){
$error_msg = "Warning: No Record was found associated to Part Number $prt";
}
echo( $error_msg );

?>

</font>

<!--displayin error end -->

</form>

BLiZZaRD
12-11-2007, 03:22 PM
<?
$error_msg = "";
if( $pdfPath == "" ){
$error_msg = "Warning: No Record was found associated to Part Number $prt";
}
echo( $error_msg );

?>


to



<? php
if( $pdfPath == "" ){
$error_msg = "Warning: No Record was found associated to Part Number $prt";
}
else {
$error_msg = "";
}
echo( $error_msg );

?>

miradoro
12-11-2007, 03:35 PM
hi

i just tried it and no luck

the message "Warning: No Record was found associated to Part Number 32445566" stays on page even after i refresh the page....

miradoro
12-11-2007, 03:36 PM
i guess what i need is the error message to display once

but once u go to another page or refresh it , the error message should be gone from page

can that be done?

BLiZZaRD
12-11-2007, 03:48 PM
I should have looked better, once you trigger the error message, it will be there, then when it comes back to the page the error message is looking for the $pdfPath, which at the top of your code you are declairing as:



$pdfPath = "";


One option is to give it a default value, which upon search is removed and replaced with the array, or replaced with nothing ("") which will then trigger the error message again.

miradoro
12-11-2007, 04:15 PM
I knew it was something wrong with the way i wrote it

im just a beginner w the php stuff :(

how would you change it?
i guess i am asking you to improve what i have

thanks

BLiZZaRD
12-11-2007, 04:27 PM
Not sure. I won't be much help here. I would need to see the whole form and everything with it. Others around here will be able to help without looking I am sure.

One thing you can try is to make the top $pdfPath = "Path"; instead of ""

Your script should replace "Path" with the array when needed, but the default won't be "" anymore.

Other than that I really don't know.

boogyman
12-11-2007, 04:32 PM
if you refresh the browser then you are just sending the same data, so the warning/error message should stay there, if new data is submitted and you are still getting this problem well then thats a matter of the default value as blizzard stated, however you do declare the error to be nothing before output is given, so I am going to lean into saying that you are just refreshing the same data.

try to submit new data ?

miradoro
12-11-2007, 04:50 PM
when i submit new data error goes away
can error go away when refreshing page?

now.... if i go to another page that has the same form, the error keeps showing
is there a way to fix that?

plssss helppppppppppp