0

this is a test code i wrote to get a value set for $rectype to insert into a table. problem I'm having is $rectype is returning 0 or empty. the files do exist since I perform a similar is_file check to start the process that leads up to this section of the coding

$dirchk1 = "/temp/files/" . $data[0] . ".doc"; // exist
$dirchk2 = "/temp/files/" . $data[1] . ".doc"; // exist

$file_1 = (is_file($dirchk1));
$file_2 = (is_file($dirchk2));

if ($file_1) {
$rectype == ($file_2 ? '3' : '1');
}

echo $rectype . "\n";
1
  • you are comparing by '==' while you want to assign by '=' Commented Dec 14, 2010 at 19:20

4 Answers 4

3

You are using == instead of =.

Sign up to request clarification or add additional context in comments.

Comments

2

You have a typo:

$rectype = ($file_2 ? '3' : '1');

Also read something about operator precedence to avoid using so many useless parentheses.

Comments

2

You need to do an assignment

$rectype = ($file_2 ? '3' : '1');

instead of a comparison

$rectype == ($file_2 ? '3' : '1');

Comments

2

As typed everywhere, you are using a comparison $expression == $expression instead of an assignment $variable = $expression;.

They didn't tell you that your code, as exposed would drop a E_NOTICE saying that $rectype is uninitialized.

It is good practice to run your code with error_reporting(E_ALL) while debugging, and that will tell you these errors and the line where they are.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.