-1

how to pass echo value to a variable by using php as i want to extract id and give its value to $prod.enter code here

$prodi=' <?php echo $cartr['id']; ?> ';

it gives me the error( Parse error: syntax error, unexpected 'id' (T_STRING) in C:\xampp\htdocs\cart.php )

feeela
  • 29,399
  • 7
  • 59
  • 71
  • 2
    What does this have to do with the Javascript, C and P programming languages? Or with Bootstrap? – Some programmer dude May 31 '18 at 08:53
  • 2
    As for your problem, are you sure you could nest single quotes? The syntax highlighting of your editor (or here on SO) should give you a hint about the answer. – Some programmer dude May 31 '18 at 08:54
  • @feeela seems like PHP but he uses `$prodi` as a JS variable. At least it looks like... – Roko C. Buljan May 31 '18 at 08:55
  • @RokoC.Buljan Yep, saw that later on… – feeela May 31 '18 at 08:56
  • 1
    By saying *`echo value to a variable`* you mean to a JS variable? Can you please clarify? – Roko C. Buljan May 31 '18 at 08:57
  • 2
    Assuming this is about giving JavaScript variables values produced by PHP, [this question](https://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript) may be a better duplicate. (It would be safer to use `json_encode()`.) If not, then I don't have a clue what the OP is trying to do. – Candy Gumdrop May 31 '18 at 09:03

2 Answers2

0

You should use double quotes after $prodi:

$prodi=" <?php $cartr = $_POST['id']; echo $cartr; ?> ";

otherwise you close the definition of your variable and than have a random id

Luca
  • 296
  • 2
  • 19
  • don't take me to serious, it was kinda obvious and your offensive behavior agrees with my opinion. But this is nothing we need to discuss on so, I'm sorry for this comment, end this conversation here and now. – Felix Gaebler May 31 '18 at 09:00
  • 1
    @FelixGaebler ah ok, I understand how my comment on Rahul's answer could come across differently than how I meant it. I deleted it now – Luca May 31 '18 at 09:03
  • i use the double quotes as mentioned in my question ,exatly return error – zain ul abideen May 31 '18 at 09:08
  • @zainulabideen I am not quite sure anymore what you are doing, but is `$cartr` supposed to be a value from a POST form(or GET of whatever)? If so, maybe the edit helped. – Luca May 31 '18 at 09:24
0

Do something like given below

  $prodi=$cartr['id'];
  echo $prodi;

OR you can do with out assigning the variable

echo $cartr['id'];
Rahul
  • 1,617
  • 1
  • 9
  • 18