We got an assignment called the “black adder.”
It was a php code debugging assignment.
The adder is a harmless-looking extremely poisonous snake. And this code was similar. I don’t think adders are black, though.
I worked on this messed-up code for about 2 hours before I realized I had not managed to set error reporting to ON on my local php installation.
By that time I had figured out how to get the code to work.
The essence of it was how php treats quotes – single and double – and how you have to enter html code so that php will echo it correctly.
I couldn’t totally figure it out so I separated the echo commands into the html sections and the variables. I know php echos the values in variables when they are placed in strings within double quotes. However, html needs its attributes double-quoted, so it is better to leave the php variables outside of the quoted html strings.
The bad code was designed to NOT error out in php, so I was trying to figure out what was wrong based on the junk that php was outputting to my browser. But until I took out all my comments and segregated all the different echoed strings I couldn’t make it calm down and work.
After that, I had a problem with isset(). It seemed to test true whether you put anything into the form array or not. However empty() was more sensitive. So I ended up using two conditional statements in my code instead of one. I could then test both if the the submit button in the form had been pushed AND and if the form text boxes had anything in them. If the form was sent empty, even half-empty, I prompted for data. Otherwise I would display the answer string and the reset link. You could enter a non-numeric character in the form and it would still function, but act as if you had entered zero.
populating a database table
My next job was to populate my database table “artitems” in my database “larryart.” This will probably be changed to “lcox0008” so it has the same name as my database at school.
I found out the the punctuation used in the SQL INSERT statement used “`” signs. I thought they were single quotes. MySQL didn’t like that! I’m not sure those characters are required, but I was following how the book author did it. I fixed that and now I have data on 19 pieces of art loaded into my database at home. So now I can play with the code needed to display the art in the browser.
Total time spent: about 4 hours.