Search code examples
phpsyntax-errorfile-exists

Parse error: syntax error, unexpected T_VARIABLE" for file_exists call


I'm using the following code to determine if a file is present in the directory pdf_Order_pdf/ which will display a working link or just and anchor link if file not present, I am a complete novice with php (as you can see) but do have a very limited understanding.

<?php
if(file_exists('pdf_Order_pdf/'.$row_Recordset1["our_ref"]'.pdf')) 
    echo 'pdf_Order_pdf/'.$row_Recordset1["our_ref"]'.pdf'; 
else 
    echo '#';
?>

the code above is in between the following html:

<a href="****code above ****">File</a>

I get the following error

Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\SwiftPHP\resultsSupplier.php on line 230

Why does this happen?


Solution

  • You forgot the . operator after $row_Recordset1["our_ref"]

    if(file_exists('pdf_Order_pdf/'.$row_Recordset1["our_ref"].'.pdf')) 
    ----------------------------------------------------------^