sanram123 Posted April 4, 2020 Share Posted April 4, 2020 (edited) 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 April 4, 2020 by sanram123 code was not formatted Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/ Share on other sites More sharing options...
benanamen Posted April 4, 2020 Share Posted April 4, 2020 Correct me if I am wrong, but you want to use the value of $id by using a completely different variable named $customerID? Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576251 Share on other sites More sharing options...
sanram123 Posted April 4, 2020 Author Share Posted April 4, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576252 Share on other sites More sharing options...
requinix Posted April 4, 2020 Share Posted April 4, 2020 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? Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576255 Share on other sites More sharing options...
sanram123 Posted April 4, 2020 Author Share Posted April 4, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576256 Share on other sites More sharing options...
requinix Posted April 4, 2020 Share Posted April 4, 2020 Have you fixed your HTML yet? After you have done that, What do you see in your browser's address bar? Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576257 Share on other sites More sharing options...
sanram123 Posted April 4, 2020 Author Share Posted April 4, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576258 Share on other sites More sharing options...
requinix Posted April 4, 2020 Share Posted April 4, 2020 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? Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576259 Share on other sites More sharing options...
sanram123 Posted April 4, 2020 Author Share Posted April 4, 2020 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" Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576260 Share on other sites More sharing options...
requinix Posted April 4, 2020 Share Posted April 4, 2020 Take another look at how the class attribute is set up. Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576261 Share on other sites More sharing options...
sanram123 Posted April 4, 2020 Author Share Posted April 4, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576262 Share on other sites More sharing options...
requinix Posted April 4, 2020 Share Posted April 4, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576263 Share on other sites More sharing options...
sanram123 Posted April 4, 2020 Author Share Posted April 4, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576264 Share on other sites More sharing options...
requinix Posted April 4, 2020 Share Posted April 4, 2020 Okay. Are you still getting the undefined index warning from that details.php?id=20597 page? 1 Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576265 Share on other sites More sharing options...
sanram123 Posted April 4, 2020 Author Share Posted April 4, 2020 (edited) 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 April 4, 2020 by sanram123 Quote Link to comment https://forums.phpfreaks.com/topic/310459-how-do-i-get-a-url-variable/#findComment-1576266 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.