1

I would like to pass product_id to a link that takes you to product_view page in echo statement which currently I cant manage. I need help with this statement I know how to do it with php inside html but not vice versa. PLZZ help. thank you

Here is my code ; echo "<a href="product_view.php?product_id=". echo $id . ">" View "".

1 Answer 1

1

There are multiple mistakes you did in your code.

First of all you have to either use different types of quotation marks or escape them in your echo statement. By the way: As you use double quotation marks just use your variables without interupting your string.

The second mistake is that you used echo inside your echo statement.

$id = 1;
// Use different types of quotation marks:
echo '<a href="' . $id . '">View</a>';
// escape your quotation marks:
echo "<a href=\"$id\">View</a>";
// or
echo "<a href=\"" . $id . "\">View</a>";

// Final example:
echo '<a href="product_view.php?product_id=' . /* do not echo here */ $id . '">View</a>';
Sign up to request clarification or add additional context in comments.

1 Comment

I was so confused with these quotation marks, I thought ı tried this final example version but apparently I didn't! Thank you so much for this great explanation. It worked. @bastian

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.