I recently started reading PHP & MySQL Novice to Professional by Kevin Yank. I ran into a problem on the second example I attempted to use in the book.
See if you get the result you expect. I’m not sure why you are getting an undefined index on firstname though, as that looks to be properly defined and if you are receiving the firstname, then that shouldn’t be a problem…
xDebug is a good thing, not sure how many new ppl will dig it though. Good thing to mention all the same, the more ppl see it the more likely they will be to seek it out and give it a try.
Could anyone explain why this is the case though? I’m using eclipse for this, and I believe it is encoded with utf-8. If that makes any difference. Thank you for all of your replies though, I really appreciate it.
And cups, thanks for that, I’m going to try that out and see how it works. Not sure if that was the issue in this case though. But about xDebug, is there much that it can do that eclipse can’t?
xDebug is a tool that helps you debug your php code. I believe you can install it as a plugin for eclipse but don’t hold me to that statement. In short, you usually press a button to tell xDebug you want to debug your code. It then watches your php execution and you can set breakpoints in your code so you can watch the execution, see the values of your variables, etc.
Another neat feature it provides is a profiler. Where it will watch your code execution and tell you what methods/functions are being called the most often and how long it takes them to run.
Actually, no I cannot, and that put me off replying to your initial post for a while.
I had experience in the past of using & when I wanted to pass xhtml strict standards for my html output back in the day, and I had it working and I recall reading on the W3C site the reasons for that, but the facts have dribbled out of my head.
I fear it will not be not easy to say exactly why it will not work for you in this instance without seeing a lot more settings, I have a feeling it will have to do with some kind of doctype, but that is just a misty memory.
Unless anyone else pipes up with a definitive answer, I would just use & and get on with things.
I would like to point out one thing: & is not the problem - actually, when you use a URL (or any attribute value) in HTML/XHTML you have to use & - every & character must be encoded as &. Using & alone is incorrect and any HTML validator will raise an error. Sure, browsers accept plain & without problems but that is because this is one of the most common (and promoted) mistakes people make (even Google Map API docs contain incorrect <script> tags with unencoded & characters!).
& cannot be the problem as it is the correct way of encoding & in HTML. Unfortunately, I have no idea what the problem might be, it looks very strange to me. Most probably it’s some trivial error that is very hard to spot. If you were able to provide the actual source code of these two files that you find problematic - that would be great help - but not pasted here as text in this forum but archived in a zip file - sometimes there can be hard to spot problems with some special characters which are hard to notice or can be lost in text transmission.
Hmm. Could you elaborate on what exactly you would need in order to figure this out? When you say the source code, do you want me to zip the actual .php files (one includes HTML) or do you want the source from the output (HTML)?
It’s worth noting that utf-8 encoding is not working on the webpage either, for some reason. And I do include a <meta> tag for utf-8, and the project in eclipse (my code editor) was set to utf-8 as well, but still my browser insists on giving me question marks where I use characters like ú/í or something like that.
Oh and as for xDebug, I really appreciate you pointing that out to me. I’d love to see which part of my code runs slower than average, as well as use some breakpoints. My PHP is pretty cluttered with echo statements at the moment, since that’s what I use to see the content of my variables, and if parts of my code are reached. Is there a reputation system in place so I could upgrade you all a bit?
Edit: sorry, I first didn’t notice I actually replied to the wrong post! Here is the corrected answer:
What I meant was that we can only see parts of your code and it doesn’t work although in should - logically. That’s why it would be good to see the complete code because the problem may be elsewhere. These things would be enough:
All code of the file that displays the link.
All code of the file that accepts $_GET data from the link and displays it on the page.
Zip for upload would be better because we would have 100% certainty we have the same code.
Agreed. I went for the simplest approach first and to come back to this later.
First, open your web page in a browser, view source and verify that when you had & instead of & that it didn’t produce & as your HTML output.
So edit your link to use &, open it in a webpage, view source, and see if you have & or if it reads &
When doing a view source, copy and paste the HTML output shown in the browser here in [ html ] [ /html ] tags (without the extra spacing) so we can see what output was generated. Another thing you can do is set the content-type via the header() function in PHP.
Example:
header('Content-Type: text/html; charset=utf-8');
xDebug is a fantastic tool! If you have troubles setting it up, please start a new thread stating your IDE and your troubles (I feel a new thread will be of more use than trying to append it to this one ;)) As for reputation system, there isn’t one that I know of, but if you feel comfortable with it, nominate any of the above members in the SPF Community Awards
Thanks, I think I just might. Running into some problems with just trying to use the breakpoints.
As for the & issue, I honestly don’t know what to tell you, but it works now. I haven’t changed anything that I’m aware of, but I have restarted my computer since the first post.
I know for a fact that the example in the book works because I had no problem with it.
So, I went back to the book to see where you might have went wrong and here’s what I think it could be. In the book, Kevin Yank says “code up” an html page, but he only shows you the info that he wants you to drop into that html file. He assumes that you already KNOW to add the rest of the information. Thus name.html should look like this:
Also, make sure that you are parsing the page through your web browser and not just finding and clicking on the file itself. Another thing, make sure that the editor that you are using is set to “utf-8” as well (most aren’t). If no of this works it might have something to do with your apache setup.
Thanks for the reply. It does work - and yeah, I do have to set it to utf-8 manually (haven’t had a look at how to make it default). But for some reason the code (unaltered) worked when I came back to it 2 days later.