Blog 5 – Problems

As mentioned in the last blog I encountered a number of issues related to getting the the UID uploaded to the database through the PHP web server. I decided to stop what I was doing and do some more research.
I went away and found some other methods of achieving what I want to accomplish. When looking I was focusing on solutions that had error checking built in. This was the problem I was having before, I knew there was an error but I couldn’t figure out where. Because I was using the PHP as a middleman the normal error checking ways couldn’t be used. These are made for when you are looking at the web page. But as I was never viewing the page and the Arduino was just giving it the information I couldn’t work out how to see the errors.
Then I found the education site Distributed Computer Systems and in the Lab; 3.2, Arduino and the Web, they cover a way of getting the errors back. In their solution the Arduino sends the information in the way I was doing previously, through a URL. It would then wait a second to let the PHP execute the MySQL query, before asking if everything completed the way it should have, from the PHP web server.

I compared what I already had to what their solution was. I noticed that they were using a GET statement instead of the POST statement to send the data from the Arduino to the PHP web server. This was a problem that I suspected in my last attempt. I changed to a GET statement in my PHP code. I check the rest of their PHP code and found that the code I was using was almost the same as theirs, so I decided to keep mine for now.
Next I looked at the Arduino code. The code that they were using to upload the data was very different. I wanted to try their solution because it had the error checking built in. Due to the way that I have formated the Arduino code in the last iteration to have a number of functions that could be called, it meant that I could easily integrate the new version. I made a new copy of my last Arduino iteration, removed the old upload code and replaced it with the new code. I uploaded this to the Arduino and gave it a test.

It ran through and said it had sent the data to the PHP web server. Then when I requested to see if the PHP had worked correctly it returned “500  Internal Server Error”.

06-09 Internal Server Error.PNG

When I looked up this error code, there was nothing that would say what the error was. This is a general error code and could mean a whole range of things. One person suggested to go look in the error logs on the server, as this may contain a more indepth error reporting.
I went to the error logs folder on my server and promptly got shut down with a permissions denied to access this file. I remembered that to access the folder, where the website files go, I had to give myself permissions and access to read and write files contained in the folder. To gain access to the log files I followed the same steps as in the setup tutorial.
There was a file in there that has all the general errors of the server. I opened it and was instantly lost. There were lots of errors, many I didn’t understand.

I decided that it was best to just run the Arduino program again, let it return the “500  Internal Server Error”, and look at the newest entry in the error log file.
Below is the new error I got back;


This meant that I had a “}” somewhere in my PHP code, where it shouldn’t be. I had a look through my PHP code and couldn’t find any “}”. I decided to use the find function in case I missed it or couldn’t see it. IT FOUND ONE……. and it was hidden;



This is why I missed it the first time round. In notepad++ when the code is wider than the page it scrolls across. My code had made it scroll across about three lines. This meant that I couldn’t see the “}”. Also as it was unexpected, notepad++ had greyed it out, meaning that it was even harder to see. Maybe this was the error I was having right from the start and I didn’t even realize.

I deleted the “}” and reran the Arduino code. It didn’t return a “500  Internal Server Error” this time but a error with my MySQL query.


In my books this was a success as the MySQL error was an easy fix. Now I have the Arduino copying the UID to the database.

One thought on “Blog 5 – Problems

  1. This totally reminds me of a problem I encountered when I was working as a programmer! It took 4 of us about 6 hours to find the error – a hidden full stop in the middle of a COBOL if statement! It was hiding totally off screen – grrr so satisfying when you finally find it 🙂

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 )

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