-3

I'm using the php below to display data from an array. I receive a parse error on line 26 (that is the following line) of the code:

    $delete = echo $field['id'];

This is the exact error message:

Parse error: syntax error, unexpected 'echo' (T_ECHO) in \path\to\file.php on line 26

hakre
  • 193,403
  • 52
  • 435
  • 836
  • echo doesn't return any value to assign to $delete – Mark Baker Dec 27 '12 at 22:51
  • `echo $delete = $field['id'];` will work if you want to assign and display at the same time. – Salman A Dec 27 '12 at 22:55
  • 1
    `echo` is a statement, not an expression. – mario Dec 27 '12 at 22:55
  • 1
    When you post a question 1.) post the exact error message (very important) and 2.) post the relevant code (not just all code). Also reduce your question to the actual point. There is no need to explain the world what you currently do, just explain the programming problem, not your life. – hakre Dec 27 '12 at 22:56
  • For PHP error messages it's always a good idea to first visit: [Reference - What does this error mean in PHP?](http://stackoverflow.com/q/12769982/367456). – hakre Dec 27 '12 at 22:57

4 Answers4

3
 $delete = echo $field['id'];

Unlike print, echo can't be used as the right hand side of an expression. If you want to both echo and assign you would need this:

echo $delete = $field['id'];

Most likely, though, these are remains of your earlier debugging and you actually just mean this:

$delete = $field['id'];

See also: the manual on echo

echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function.

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
2

You have

$delete = echo $field['id'];

which should be

$delete = $field['id'];

without the echo.

Musa
  • 96,336
  • 17
  • 118
  • 137
  • It's not clear what is wanted, so I edited your answer (just exemplary, could have been any of the others) to echo and assign - just in case that was wanted. OP wrote it's for echoing things. – hakre Dec 27 '12 at 22:58
  • @hakre the code showed that he wanted $delete in a variable to be echoed later(before you stripped it away) – Musa Dec 27 '12 at 23:00
  • But this does not explain why OP used echo at this position. The line 26 in itself (next to whatever is done with the variable later on) wants to echo. Just saying, I won't edit your answer a second time. – hakre Dec 27 '12 at 23:03
  • Musa is correct. Thanks for refining my post, hakre. – user1933231 Dec 27 '12 at 23:04
2

$delete = echo $field['id']; should be $delete = $field['id'];

Echo Return Values

"No value is returned."

Reference

Ricardo Alvaro Lohmann
  • 26,031
  • 7
  • 82
  • 82
0

My recommendation is, put only one form outside the table with the method and action and only one input hidden, use one input button(not submit) in each row, setting for each onclick="submit($delete);".

function submit(val){
  document.getElementById("yourHiddenInput").value = val;
  document.getElementById("yourForm").submit();
}
HMarioD
  • 842
  • 10
  • 18