Lets says you have a database of cars. You have added a button to the List page that should update selected cars statuses as 'Sold'. Your code looks good and passes syntax check still doesn't work when you run your application. The worst of all - it doesn't produce any visible errors. In this article I'll show you how to catch errors like this one.
We are going to need either Chrome or Firefox with Firebug addon installed. Our screenshots are taken in Chrome. Open your list page, hit F12 to display developers tools panel and proceed to Network tab. You should see something like this:
Now select a few records and click 'Update Selected'. A new entry appears under Network tab - browser executes buttonhandler.php (buttonhandler.asp in ASPRunnerPro) file where our server side code is stored. If we expand Response tab we can see our error description if any.
In this specific case it says the following under Error description:
The Microsoft Jet database engine cannot find the input table or query 'car'. Make sure it exists and that its name is spelled correctly.
It looks like we have missplled the table name in our code. Replacing 'car' with 'cars' fixes the issue. This was definitely helpful though some events can be tens or hundreds lines of code long and single error message doesn't provide much help. To find the exact line of code that produces the error scroll down the content of Response tab to find the entry that points to buttonhandler.php file. Here it is:
This also points to the fact that something is not right with our SQL query.
Additional troubleshooting tips
You may want save a few troubleshooting steps printing your SQL Queries on the web page instead of executing them. This way you can see what exactly is happening on the server and catch syntax errors faster. To do so assign SQL queries to result["txt"] variable (result("txt") in ASP) and print it on the page using the following code in ClientAfter event.
Sample server PHP code
- foreach($keys as $idx=>$val)
- $sql = "update car set Status='Sold' where id=".$val["ID"];
Sample server ASP code
- For n = 0 To keys.Count-1
- sql = "update car set Status='Sold' where id=" & keys(n)("ID")
- result("txt") = result("txt") & sql & "<br>"
And here is how this looks in action: