-3

I am trying to insert a a href into php to add the items to the basket. but it is giving me the following error:

Parse error: syntax error, unexpected 'file_id' (T_STRING), expecting ',' or ';' in mproducts.php on line 96

Here is my code:

echo '<a href="mproducts.php?page=mproducts&action=add&id<?php echo $row['file_id']?>">Add to Basket</a>';
chris85
  • 23,846
  • 7
  • 34
  • 51
Jub
  • 41
  • 7

1 Answers1

0

Two things, you don't use PHP tags inside PHP statements, and you join (or "concatenate") echo statements with either periods or commas.

Like this...

echo '<a href="mproducts.php?page=mproducts&action=add&id=', $row['file_id'], '">Add to Basket</a>';

Or...

echo '<a href="mproducts.php?page=mproducts&action=add&id=' . $row['file_id'] . '">Add to Basket</a>';
Coffee'd Up Hacker
  • 1,356
  • 11
  • 23
  • Oh I understand now. Thank you very much – Jub Jun 16 '16 at 17:33
  • Note the commas aren't concatenating, that is outputting each part. If commas are used outside of `echo` for concatenating that will fail. – chris85 Jun 16 '16 at 17:34
  • @chris85 Yes. Technically using commas with `echo` isn't called "concatenation", but it is does accomplish the same thing and is slightly faster. And yes, `echo` is also about the only place where commas are used in this manner. – Coffee'd Up Hacker Jun 16 '16 at 17:40