Troubleshooting custom buttons in PHPRunner and ASPRunnerPro applications

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:

  1. <td nowrap="nowrap">#3.&nbsp;</td>
  2. <td nowrap="nowrap">buttonhandler.php:40</td>
  3. <td nowrap="nowrap">buttonHandler_Update_Selected</td>
Now we can open buttonhandler.php file in any text editor (Notepad++ recomended) and find line 40:

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.

  1. ctrl.setMessage(result["txt"]);

Sample server PHP code

  1. $result["txt"]="";
  2. foreach($keys as $idx=>$val)
  3. {
  4. $sql = "update car set Status='Sold' where id=".$val["ID"];
  5. $result["txt"].=$sql."<br>";
  6. //CustomQuery($sql);
  7. }

Sample server ASP code

  1. esult("txt")=""
  2. For n = 0 To keys.Count-1
  3. sql = "update car set Status='Sold' where id=" & keys(n)("ID")
  4. result("txt") = result("txt") & sql & "<br>"
  5. 'CustomQuery(sql)
  6. next

And here is how this looks in action:

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>