-1

I want to send a value using the get method. The code is something like this

<td><a href="cart-remove.php?id={$row['id']}" class="remove_item_link"> Remove</a></td>

This value i want to send is stored in $row['id'].This is not my code its from my instructor (very popular website with around 30k people having enrolled in the course so far but i can't name them here), see this

instructors question

but if i type exactly like he/she did i will get this error.

enter image description here



Found this answer on stackoverflow (from 2013). But when i use it like this

<?php

$id=$_GET['id'];
echo "hey".$id;

I get a output like this hey{$row['id']}

I have tried this but it doesn't work either

<td><a href="cart-remove.php?id={$row[\'id\']}" class="remove_item_link"> Remove</a></td>

How do i get this value in the cart-remove.php page? I know answers some from this question work but i am trying to keep my code similar to my instructors code as he is gonna rate the project. Also, this answer(mentioned above) was from the same thread.

4
  • <td><a href="cart-remove.php?id=<?=$row['id']?>" class="remove_item_link"> Remove</a></td> No? or didn’t I understand the question ?! Commented Apr 22, 2020 at 18:39
  • @ScreamX Thank you it worked. But i still don't understand why my instructor and that answer from 7 years ago use {} instead of <? >. Is there some way that works too?? That method got deprecated or something? Commented Apr 22, 2020 at 18:49
  • I think he mean something like that: <?php echo "<a href='page2c.php?myNumber={$array1}&myFruit={$array2}'>Send variables</a>"; ?> Commented Apr 22, 2020 at 18:52
  • @ScreamX used it like this <?php echo " <a href='cart-remove.php?id={$row['id']}' class='remove_item_link'> Remove</a>" ?> It works.Please post your complete answer so i can mark it as accepted answer. You deserve much love <3. Commented Apr 22, 2020 at 19:08

3 Answers 3

2

At the request of the author of the topic. All the plain HTML in your code will be ignored by the PHP compiler and passed to the web browser unchanged, so you need to open the <?php handler.

<td><a href="cart-remove.php?id=<?=$row['id']?>" class="remove_item_link"> Remove</a></td>

and your instructor probably meant the following conclusion:

<?php echo "<td><a href='cart-remove.php?id={$row['id']}' class='remove_item_link'> Remove</a></td>"; ?>

but, this will only work if the text is already in the php handler

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

1 Comment

single inverted comma for href and class attributes.
0

The way you're doing it would only work if this were part of an echo statement with a double-quoted string. But you're outputting the HTML direectly, not with echo, so you can't use string concanation or substitution.

You need to do it the same way all the other $row elements were embedded on previous lines of the script.

<td><a href="cart-remove.php?id=<?php echo $row['id']; ?>" class="remove_item_link"> Remove</a></td>

3 Comments

Thank you it works fine. I ran it when ScreamX commented. But i still don't understand why my instructor and that answer from 7 years ago use {} instead of <? >. Is there some way that works too?? That method got deprecated or something?
The instructor made a mistake. He also said "inside single quotes", but variable substitution only works inside double quotes.
Thank you for your time. It seems if you're already inside echo you can use both of those stuff {} and ' '. But this problem page was 6 pages long, I think my instructor did miss out on stuff XD.
0
<td><a href="cart-remove.php?id=<?=$row['id']?>" class="remove_item_link"> Remove</a></td>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.