-1

I am trying to create a table to help out a friend with timesheeting, however I am getting a PHP error and seem to be going round in circles

<td >".$Thursday_Job_1_Lunch." mins</td>
<td>" if (empty($Darren_Thursday_Job_1)) && ($Darren_Thursday_Job_1_Same == 'OFF')
    echo "No Darren;"
} 
elseif { $Darren_Thursday_Job_1_Same =='ON' echo "Darren did the same"; }
else { echo .$Darren_Thursday_Job_1;}

"</td>

It's passed from HTML, Darren_Thursday_Job_1_Same is a checkbox to say that Darren has done the same, else its meant to echo whats in the input box and if Darren is "Off" and the text input is empty it is meant to say nothing.

Parse error: syntax error, unexpected T_IF in /home/a2687257/public_html/test3.php on line 227

is the error that it is throwing at me.

thanks for the replies,

Here is a more fuller portion of the code:

$message = "
Hi Rhonda,<br/><br/>

Here is my time sheet for this week<br/><br/>
<style>
table, td, tr {
    align:centre;
    }
</style>
<table>
  <tr>
    <th >Day</th>
    <th >Date</th>
    <th >Location</th>
    <th >Start Time</th>
    <th >End Time</th>
    <th >Total Time</th>
    <th >Lunch</th>
    <th >Darrens</th>
  </tr>
  <tr bgcolor='#d7f2ff'>
    <td  rowspan='3'>Thursday</td>
    <td  rowspan='3'>".$Thursday_Date."</td>
    <td >".$Thursday_Job_1."</td>
    <td >".$Thursday_Start_Time_Job_1_Hours.".".$Thursday_Start_Time_Job_1_Minutes."</td>
    <td >".$Thursday_Finish_Time_Job_1_Hours.".".$Thursday_Finish_Time_Job_1_Minutes."</td>
    <td >".$Thursday_Job_1_Total_Hours."hours ".$Thursday_Job_1_Total_Minutes." mins</td>
    <td >".$Thursday_Job_1_Lunch." mins</td>
    <td>" if (empty($Darren_Thursday_Job_1)) && ($Darren_Thursday_Job_1_Same == 'OFF')
        echo "No Darren;"
    } 
elseif { $Darren_Thursday_Job_1_Same =='ON' echo "Darren did the same"; }
else { echo .$Darren_Thursday_Job_1;}

"</td>
  </tr>
  <tr bgcolor='#d7f2ff'>;
   <td >".$Thursday_Job_2."</td>
    <td >".$Thursday_Start_Time_Job_2_Hours.".".$Thursday_Start_Time_Job_2_Minutes."</td>
    <td >".$Thursday_Finish_Time_Job_2_Hours.".".$Thursday_Finish_Time_Job_2_Minutes."</td>
   </tr>
  <tr bgcolor='#d7f2ff'>
    <td >".$Thursday_Job_3."</td>
    <td >".$Thursday_Start_Time_Job_3_Hours.".".$Thursday_Start_Time_Job_3_Minutes."</td>
    <td >".$Thursday_Finish_Time_Job_3_Hours.".".$Thursday_Finish_Time_Job_3_Minutes."</td>
   </tr>

I do have <?php at the top too and the bottom

Prix
  • 19,417
  • 15
  • 73
  • 132
  • `" If` needs to be `". if` simple. ( with the . dot ), by the by the T_IF is the php interpreters token for an IF block, T[oken]_IF so this would be a php Parser error. : ) cheers. – ArtisticPhoenix Jul 03 '16 at 08:33
  • There is something missing before the `if (empty($Darren_Thursday_Job_1))` . Can you post a larger portion of your code, some lines earlier? – PaulH Jul 03 '16 at 08:37
  • PaulH its the Dot that is missing. – ArtisticPhoenix Jul 03 '16 at 08:37
  • 2
    @ArtisiticPhoenix I doubt a `.` solves it, since `"string" . if (true) echo "string;"` makes no sense – PaulH Jul 03 '16 at 08:38
  • Your right Paul there is much much more than that going on. That just jumped out at me. – ArtisticPhoenix Jul 03 '16 at 08:50
  • @JasonCrooks in the future don't answer to your own question to add more content, there is a `EDIT` button right below your question you can use to add more content to it. As for the content added, right at your first `if` you forgot to add the opening bracket `{`, at your `elseif` you but the condition inside the bracket which is wrong. and you forgot to add the append dot before your if and after your else. – Prix Jul 03 '16 at 10:02

2 Answers2

0

As I said in the comments you just need the concatenation ( never mind what i said in the comments this is a mess )

 <td >".$Thursday_Job_1_Lunch." mins</td>
 <td>" if (empty($Darren_Thursday_Job_1)) && ($Darren_Thursday_Job_1_Same == 'OFF')
  echo "No Darren;"
  } elseif { $Darren_Thursday_Job_1_Same =='ON' echo "Darren did the same"; } else { echo .$Darren_Thursday_Job_1;}

Should be something like this.

  echo "<td >".$Thursday_Job_1_Lunch." mins</td>td>";
  if (empty($Darren_Thursday_Job_1) && $Darren_Thursday_Job_1_Same == 'OFF'){
      echo "No Darren";
  } elseif ( $Darren_Thursday_Job_1_Same =='ON' ){
      echo "Darren did the same";
  } else {
      echo $Darren_Thursday_Job_1;
  }
  echo "</td>";

hard to tell what the code is when half is missing.

so what did I change?

Assumed this echo " at the start

add ; at the end of the first assumed echo.

removed ) after empty( ... ))

removed ( after the &&

added { after the if(...)

changed ;" to "; after the echo in the if.

What is that 7 errors in 3 lines of code. You do have <?php at the top of the page right, sorry but I have to ask. In this code remember you have to match pairs of these " , } ), they all need pairs. then you have to end lines with ; but not blocks, blocks are like loop blocks and if blocks.

UPDATE I missed the elseif originally, I'll leave figuring out what was fixed in that as an exercise to the reader.

UPDATE2:

after seeing the complete code, what you need to do is replace the echos with

   $message .=

Unless you really want to just echo. It in any case, I don't think you can inline an if with just the dot ., something like this...

  $message = " .... bla bla bla ( dont really want to copy all that :( )
  <td >".$Thursday_Job_1_Lunch." mins</td>td>";
  if (empty($Darren_Thursday_Job_1) && $Darren_Thursday_Job_1_Same == 'OFF'){
     $message .= "No Darren";
  } elseif ( $Darren_Thursday_Job_1_Same =='ON' ){
     $message .= "Darren did the same";
  } else {
     $message .= $Darren_Thursday_Job_1;
  }
    $message .= "</td>";

  echo $message;
ArtisticPhoenix
  • 21,464
  • 2
  • 24
  • 38
0

PHP is so beautiful that you can take one piece of code, make a function of it and then call it anywhere in your php file. If you are experience this problem try using another approach etc:

   function my_func($par) {
    if (empty($Darren_Thursday_Job_1)) && ($Darren_Thursday_Job_1_Same == 'OFF'){
        echo "No Darren;"
    }elseif ($Darren_Thursday_Job_1_Same =='ON') {
        echo "Darren did the same";
    }else {
        echo .$Darren_Thursday_Job_1;
    }
}

so now just simply call ur function where u want it just like this:

$result_of_my_func = my_func($data);
    echo $result_of_my_func;
The Bumpaster
  • 944
  • 7
  • 20