Cracking the Code, Cracking Up

Ok, so I had a crack (ok, that’s all the wisecracks…ok, that was another) at the first of the PHP challenge exercises yesterday (add a field for the user to enter their country of origin) and finally solved it. It took quite a bit of time (it took long than I’ll admit to, can’t believe I’m that persistent). It was slow because I had to remind myself to think in fine detail, ie, what places and how many places are affected when something changes, and make sure I’ve changed it in every place where might be relevant.

My stumbling block: the text entered into the message field was populating in the country field and vice-versa. After combing through the PHP code to make sure things were in the correct place and referring to the correct elements, I went into the MySQL database, made sure the field data types were correct, even deleted and re-added them, etc, etc. Yes, swapping them in the HTML file worked but that’s not logical–and it’s cheating! I ended up finding a similar issue on a bulletin board, and found that I hadn’t completely and exactly matched the arguments in the IF function–that is, in all three levels: IF, THEN and ELSE. Anyway, happy me, but I find if I reload the page, it repeats the message even after the text entry fields have cleared. I’m pondering that at the moment and will see what I can do about that. When I’ve got some time I’ll have a go at the phone number validation field too (glutton for punishment)!

Although the trial-and-error process is long and drawn out (particularly because I know so little about programming in general and PHP in particular, and I’m more a visual person) I gained a lot. I learned much more about managing the MySQL database eg, managing the fields, updating and so on, than if it had all gone perfectly. All this will streamline things the next time I’m doing a task. It also got me into the headspace that programming/scripting means giving instructions (and plenty of them) at a micro level–everything must be declared/stated. And code should be abundantly commented and clear to read! I saw some articles on readable code; thought this one was one of the more easily understood.

I think I’ll be more efficient next time. Ok, that’s it from me, go take a look at both my exercises if you like. Oh, and I thought I’d try applying some of the stuff we learned with CSS. Next will be a menu that is the same for all pages on my site–Alastair mentioned PHP as a method of doing that. And I’m still in the process of cleaning up that code to see if I can get it validated as XHTML 1.0 Strict.



design – Improving Code Readability – Stack Overflow viewed 4/14/2012 2012, <>.

Julie-Home Page viewed 4/14/2012 2012, <>.

PHP To MySQL Table -> Inserting Into Wrong Fields – PHP | Dream.In.Code viewed 4/14/2012 2012, <>.

Post a comment or leave a trackback: Trackback URL.


  • […] The more I try and figure something out the deeper I get (but still no solution). I mentioned here that I was working on the challenge exercise for the guestbook, which involved validating the […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: