ITC280 – Adder, etc.

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.

Advertisements

One Response to “ITC280 – Adder, etc.”

  1. Bill Says:

    Larry,

    Too bad your error reporting wasn’t on for your hosting company. I had hopes you would be able to see the native errors created by PHP, and let the language lead you to the solutions.

    Good job on getting it working!

    On the value of using isset() vs empty(). From my recall, empty() treats a string of zero length and the number zero as true. Sometimes I’ll pass the number zero to indicate no known record (the zero is not available as an autonumber).

    Using empty() on this field would draw a false positive, while isset() would not.

    There are places where empty() works better, but in my experience they are the exception.

    Bill

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s