Jump to content

Recommended Posts

I have the following code:

 echo (" <td class='text-center'><a class='btn btn-xs btn-primary' href=details.php?id=$id >Details</a></td> ");

and am trying to pull the value from the customer ID that is passed into $id.

I am trying to get the value using :

 $customerID = $_GET['id']; 

but it is not working. I get an error message saying Notice: Undefined index: id in  "my folder name" 

Edited by sanram123
code was not formatted
Link to comment
https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/
Share on other sites

3 minutes ago, benanamen said:

Correct me if I am wrong, but you want to use the value of $id by using a completely different variable named $customerID?

Yes, what I'm trying to do is to create a variable which I named $customerID that will hold the value of $id within my first statement. I hope that made sense. 

10 minutes ago, requinix said:

Fix your HTML. Attributes need quotes. Your href does not have one. Add them.

Regarding your problem, are you clicking that link in your browser? Are you talking about getting that ID from within details.php?

I apologize for the issues in my question. I will clarify. I have two files. One is customers.php and the other is details.php. Within the customers.php I have the code 

echo (" <td class='text-center'><a class='btn btn-xs btn-primary' href=details.php?id=$id >Details</a></td> ");

Within the details.php file I have the code 

 $customerID = $_GET['id']; 

Where I am trying to get the ID from the customer.php file and save it in the $customerID variable. 

12 minutes ago, requinix said:

Have you fixed your HTML yet? After you have done that,

What do you see in your browser's address bar?

Yes! I used  single quotes and now my code looks like: 

 echo ("<td class='text-center'><a class='btn btn-xs btn-primary' 'href=details.php?id=$id' >Details</a></td>");

In my address bar I currently see 

localhost/PHPClassWork/myfilesname/A10/details.php

Where I am testing the code within the details.php file. 

2 minutes ago, sanram123 said:

Yes! I used  single quotes and now my code looks like: 


 echo ("<td class='text-center'><a class='btn btn-xs btn-primary' 'href=details.php?id=$id' >Details</a></td>");

Do you see how the quotes work with the class attribute? That's the correct usage. Compare with what you did for the href...

2 minutes ago, sanram123 said:

In my address bar I currently see 


localhost/PHPClassWork/myfilesname/A10/details.php

Where I am testing the code within the details.php file. 

Can't get values from the URL if there are no values in the URL.

Have you been clicking the Details links?

10 minutes ago, requinix said:

Do you see how the quotes work with the class attribute? That's the correct usage. Compare with what you did for the href...

Can't get values from the URL if there are no values in the URL.

Have you been clicking the Details links?

Now I'm getting an error message, I changed the code to :

echo ("<td class='text-center'><a class='btn btn-xs btn-primary' "href=details.php?id=$id" >Details</a></td>");

I just tried clicking the details link and received the error message Parse error: syntax error, unexpected 'href' (T_STRING) in "customer.php" 

5 minutes ago, requinix said:

Take another look at how the class attribute is set up.

I'm at a total loss. I set up the whole string in double quotes so that PHP evaluates the whole string. The details link was working fine before I added any quotes to the href so I'm not sure how the href is supposed to be set up if it's not single or double quotes or no quotes. 

Perhaps you've been looking at this for too long and so can't see it.

class, equals sign, single quote, the various classes, single quote

Your first change to href was:

single quote, href, equals sign, the URL, single quote

Compare where the quotes were. Your second attempt was the same except you put in double quotes, something which the class attribute was not using, which is no more correct than it was with single quotes except the double quotes conflict with the ones you were using in PHP.

One more time. And then, after you've clicked then link, tell me what the URL in the address bar is.

8 minutes ago, requinix said:

Perhaps you've been looking at this for too long and so can't see it.

class, equals sign, single quote, the various classes, single quote

Your first change to href was:

single quote, href, equals sign, the URL, single quote

Compare where the quotes were. Your second attempt was the same except you put in double quotes, something which the class attribute was not using, which is no more correct than it was with single quotes except the double quotes conflict with the ones you were using in PHP.

One more time. And then, after you've clicked then link, tell me what the URL in the address bar is.

Thank you for your patience! I believe you're right. I've been stuck for a few hours. I changed the quotes to: 

echo ("<td class='text-center'><a class='btn btn-xs btn-primary' href='details.php?id=$id' >Details</a></td>");

And now when I click the link in the URL i see 

localhost/PHPWork/myfiles/A10/details.php?id=20597 

for the details ID that I clicked.

18 minutes ago, requinix said:

Okay. Are you still getting the undefined index warning from that details.php?id=20597 page? What's the rest of the code in the file?

 

I tested it again and am not. Thank you so much for your patience! It's grabbing the value now. 

Edited by sanram123
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.