Weblog Of Nirandas | home

Developer From INDIA

codeigniter: retrieving the database error message and error number

clock July 31, 2008 11:40 by author

Yes, nobody want errors to happen in their code, however when they happen, you must be able to retrieve full information about them no matter which language or framework you use. I came across this issue while developing a site with codeigniter. I looked through the user guide but was not able to find it. However after searching through the web I came across some forum posts answering my concerns. Although I missed the url, Here is the name of the function using which you can retrieve the info about the errors.

$this->db->_error_message()
Returns the error message from the database depending upon the database driver being used. For MySql, it uses mysql_error()
$this->db->_error_number()
Returns the error number from the database depending upon the database driver being used. For MySql, it uses mysql_errno()

I didn't find it documented anywhere so I am posting here. Let me know if anyone have references to it in the user guide.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


asp.net mvc: Is that username available?

clock July 29, 2008 16:44 by author Nirandas

I been using prototype for few of my project lately, however, I been hearing some wonderful things about jquery so decided that it is the right time to give it a shot. Here is what I tried to implement with jquery on asp.net mvc. I decided to add the ability to automatically check whether the username given by the user on the registration page is already taken or is available. For this I added a new action on the account controller named "check". This action returns a ContentResult containing the text to display. Code follows:

public ContentResult Check(string id) { if (Provider.GetUser(id, false) == null ) return Content(""); return Content("The username is already taken."); }

this function takes the username entered by the user as its parameter and checks if the username is available or not. If available, it returns nothing and if the name is already taken it returns the error message. After getting this done, now we will have a look at the changes made to the registration page's view.

The main change other than adding the jquery magic, is to add a span where to display the output from our check action. We will place it just after the text field for entering username. Modified table row of the username field is shown below.

<tr> <td>Username:</td> <td><%= Html.TextBox("username") %> <span id="isUsernameAvailableResult"></span> </td></tr>

after this, we will add the following script to the view. Note: I have included the jquery.js in this snippet, in real world you would probably have it included inside your master page.

<script src="/content/js/jquery-min.js" mce_src="/content/js/jquery-min.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> $(document).ready(function(){ $("#username").blur(function(){ $("#isUsernameAvailableResult").load( "check/" + escape(document.getElementById("username").value) + ".aspx"); }); }); </script>

Here we first add the anonymous function containing the actual code which does the ajax call to the blur event of the username text box. We do this inside the jquery special document.ready event)

The code just selects the span to contain the result and load the output of the ajax call into it. Here the request url is "/account/check/[user entered name here].aspx". Note: I use a modified routing rule in which the url always ends in ".aspx". This is to make it work it on iis 6 also without any big changes.

jquery is a great tool to have, and with the introduction of asp.net mvc, integrating jquery with asp.net is easyer than ever. Enjoy,

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Best possible url format in asp.net mvc on IIS6

clock July 25, 2008 05:45 by author

I been interested in asp.net mvc since its preview2 release but really its now that I am playing with it. I have downloaded the asp.net mvc preview4 and is currently enjoying the cool new method of developing asp.net websites.

An important feature of asp.net mvc framework is its pretty urls and ability to map incomming requests to controllers and action like other mvc frameworks. However the url format like "/blog/archive/hellow-world" would not work on iis6 by default. For these types of urls to work on iis, we either have to setup iis to route all incomming requests to asp.net or use a different url format.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


digg: Darn! The picture and your input did not match up.

clock July 21, 2008 10:49 by author

In these times when having an user account at any of the social bookmarking sites is a normal thing for
any internet savvy person, I also tried to join the party. at http://www.digg.com. Like any membership based site, digg also want that its users must be real persons. Usual, every website would want that. What is the method to insure that the registrant is indeed a human? Yes, you guessed right! "CAPTCHA"!.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Validating username with RegularExpressionValidator

clock July 19, 2008 14:08 by author

The asp.net validation controls enable us to quickly validate user inputs in a variety of ways. This post talks about using RegularExpressionValidator to validate username in a registration page. Often we want to limit the types of characters which can be allowed in the username. For this example, we would only allow the following characters. a to z, A to Z, 0 to 9. By using a Regular expression validator, not only we successfully validate the user input, we can also provide immediate response to the user regarding the correctness of the username entered. So, let's delve into the code.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Max length property for textarea

clock July 17, 2008 14:16 by author Nirandas

Here is a solution using javascript which helps to restrict the
number of letters which can be entered in a html textarea field. Effectively providing the textarea field with a max length property.

<script type="text/javascript" language="javascript">
function CheckMaxLength( txt, size, error)
{
error = document.getElementById( error);
if( txt.value.length >= size)
{
error.style.display = "";
if(txt.value.length > size)
txt.value = txt.value.substr( 0, size);

return;
}
error.style.display = "none";
}
</script>
<textarea id="f" rows="4" cols="20" onkeyup="CheckMaxLength( this, 10, 'error_message');" >
</textarea>
<span style="display:none;" id="error_message"> The textarea is full!</span>

Here we declare a function CheckMaxLength() which takes 3 parameters.
First is the textarea which to check, second is the maximum size allowed and the third is the id of the element which contains the message to display.
In the html markup, we have a textarea who's onkeyup contains a call to the CheckMaxLength() function providing the required arguments.
We also have a hidden span with the error message which we want to display to the user when the textarea reaches its maximum length.
We should be providing the id of this element as the third parameter to the CheckMaxLength() function.

The code inside the function simply checks if the length of the text in the textarea is greater or equals to the size provided.
If so, it sets the element's display style property to "" containing the error message making it visible. and set the text of the textarea
after taking the first size characters. This method stops users from pasting large text into the textarea as the onkeyup event will be triggered while pasting and the size will be checked.
The function then sets the display style property of the error message element to "none" hiding it if the length doesn't exceeds the provided size.

You can modify the script and its action according to your needs and make it a useful and perfect snippet to meet your circumstance.

Happy hacking!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Who Am I?

I am Nirandas - a developer from INDIA

Sign in