0

I have this code:

<p><a href="./page.html?msubject=<?php echo $_GET['msubject']?>&subject=thingy">Page</a></p>

According to this previously asked question, it should be right,

yet I get errors of a

malformed URI reference and subject being an unknown entity.

6
  • urlencode() Commented Apr 12, 2017 at 5:46
  • Closing PHP tag is missing Commented Apr 12, 2017 at 5:46
  • maybe you forgot the "?" at end <?php echo $_GET['msubject']**?**> Commented Apr 12, 2017 at 5:47
  • @manian When editing for formatting, I accidentally deleted it. It's not the problem. What else could be the problem? Commented Apr 12, 2017 at 6:14
  • @Andreas Would the corrected code be: <a href=urlencode("./page.html?msubject=<?php echo $_GET['msubject']?>&subject=thingy")> Commented Apr 12, 2017 at 6:15

4 Answers 4

1

You didn't close your PHP tag correctly.

<?php echo $_GET['msubject']>

change to this

<a href="<?= urlencode('./page.html?msubject=' . $_GET['msubject'] . '&subject=thingy') ?>">Page</a>
Sign up to request clarification or add additional context in comments.

2 Comments

When editing for formatting, I accidentally deleted it. It's not the problem. What else could be the problem?
Ok then try what other guys suggest, use urlencode, I will edit my answer. @p26528
0

check if the msubject doesn't have spaces. I'm not a php programmer but I know I have to urlencode my string before loading them in an URL

2 Comments

How would you urlencode before putting it into the URL? Can it not be done in 1 go? The example on php.net shows it being used on the php part, which would make it so the php would not run.
like I said I'm not a php developer but I hope this helps php.net/manual/en/function.urlencode.php
0

Try this

<p><a href="./page.html?msubject=<?php echo $_GET['msubject'];?>&subject=thingy">Page</a></p>

You miss **<?php ?>**

Comments

0

Please try this code,

<?php $query = array('msubject' => $_GET['msubject'],'subject' => 'thingy'); ?>
<a href="./page.html?<?php echo http_build_query($query, null, '&amp;', PHP_QUERY_RFC3986); ?>">Page</a>

Please refer the below url for 'http_build_query' function

http://php.net/manual/en/function.http-build-query.php

Comments

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.