0

I am learning php right now.

I have a anchor that shows the php value I want to pass. But the problem is, I can't get the said value.

Here is my anchor code in html:

<a href="#?pName='.$prodName.'">Add</a>

Here is the link that displays the value:

http://localhost/pphcompany/index.php#?pName=family1

Here is my php code to get the value of pName:

$prodName = $_GET['pName'];

But it's not working and returns an error that says:

Undefined pName

Please anyone could help me get that value?

Jay Marz
  • 1,861
  • 10
  • 34
  • 54

1 Answers1

0

That # is killing your get. Everything behind # is not being parsed as a $_GET, but rather as a link to the same page's portion with that name. Edit your code to:

<a href="?pName='.$prodName.'">Add</a>

And you should be fine.

Francisco Presencia
  • 8,732
  • 6
  • 46
  • 90
  • i tried removing the # but the page refreshing. all my input are lost – Jay Marz Sep 14 '13 at 18:22
  • The part after `#` isn't sent to the server and doesn't actually make a difference to the `$_GET` value. – Amal Murali Sep 14 '13 at 18:24
  • Yes, that's what is expected to happen when you navigate away to another url. Please can you explain what you want to achieve in your original post, which might also stop this question from being a duplicate? – Francisco Presencia Sep 14 '13 at 18:24
  • I want to get that value to be displayed in a `popover`. but since the page is refreshing, the popover will not be displayed. – Jay Marz Sep 14 '13 at 18:27
  • For that you should use javascript (or jquery) if you don't want the page to refresh, or submit the form and once submited display the popover. PHP works in this way: it is executed in the server and then the html file is sent to the browser. Once it is in the browser PHP is not executed any more except if you submit the page. So you cannot retrieve a value from an input and display in a popover with PHP, you need another technology (javascript) or submitting the form. For the latter you'd use an ``, for the former a link like this: `Add` – Francisco Presencia Sep 14 '13 at 19:13