Home arrow Web Standards arrow Page 3 - Getting Connected with Firefox and Chrome
WEB STANDARDS

Getting Connected with Firefox and Chrome


In this third part of a four-part article series on configuring Firefox for Chrome and a server, you'll learn how to connect PHP to MySQL, call the MySQLi API, and more. This article is excerpted from chapter four of Programming Firefox, written by Kenneth C. Feldt (O'Reilly, 2007; ISBN: 0596102437). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 4
June 19, 2008
TABLE OF CONTENTS:
  1. · Getting Connected with Firefox and Chrome
  2. · Connecting PHP to MySQL
  3. · Calling the MySQLi API, continued
  4. · Troubleshooting

print this article
SEARCH DEVARTICLES

Getting Connected with Firefox and Chrome - Calling the MySQLi API, continued
(Page 3 of 4 )

Within the JavaScript code, first we need to make certain we are responding to the correct command, so we add a global variable at the top of the source file to hold the last command issued:

  var K_XUL_NAMESPACE = "http://www.mozilla.org/keymaster/
      gatekeeper/there.is.only.xul";

  var USER_LOGGED_IN = 0;

  var lastCommand = "";
 

and modify the doLogin function to save the last command sent:

  function doLogin(event) {

  try { // try
  var theArgs = new Array;
  theArgs[0] = new commandArg("un",document.getElementById("userName").value);
  theArgs[1] = new commandArg("pd",document.getElementById("password").value);
 
lastCommand = "login";
  doServerRequest("login",theArgs);
   } // try
   catch (e) { //
   
alert("doLogin exception: " + e);
   }//
  }

When processing the server response, we use the JavaScriptsplit()function to break our comma-delimited responses into an array of name-value pairs. We then compare the value of the first entry to"true"before extracting the second returned value and setting the status text:

  function retrieveServerResponse() {
   if (theServerRequest.readyState == 4) { // all done
    // Check return code
     if (theServerRequest.status == 200) { // request terminated OK
      dump("Received from server: " + theServerRequest.responseText + "\n");

      //
      var theResults = theServerRequest.responseText.split(",");
      //

      var rCode = (theResults[0].substring((theResults[0].indexOf("=")+1),
                                theResults[0].length)).toLowerCase();

      if (lastCommand == "login") { // process login command

      if (rCode == "true") { // everything OK, we know next parameter is
                            
// session info
       var lastSession = "Last login was ";
       lastSession += (theResults[1].substring((theResults[1].indexOf("=")+1),
                              
theResults[1].length)).toLowerCase();
       loginOK();
       setStatusText(lastSession);

      } // everthing OK
     
else { // user NG
       loginFail();
       setStatusText("No user logged in");
      } // user NG

     } // process login command

    } // request terminated OK
    else { // something is wrong
     alert("Response failed.");
    } // something is wrong
   } // all done
  }

This version of the program will now log into the database, and if the username and password match (and the account is active), the welcome screen will include a status line along the bottom of the display reporting the last date and time of the userís login:

  Last login was 0000-00-00 00:00:00

All zeros appear because our initial script to create the database tables did not set an initial date in the database. Once we log in under a valid account name, the next login will yield a more welcoming message. 


blog comments powered by Disqus
WEB STANDARDS ARTICLES

- Mozilla Popcorn Maker 1.0 Makes Videos More...
- Completing a Configuration for Chrome and a ...
- Getting Connected with Firefox and Chrome
- Configuring Servers and Databases with Chrome
- Configuring Firefox for Chrome and a Server
- Designing the Elements of a Web Page
- Matching div heights with CSS and JavaScript
- Forms
- Get Down With Markup
- If I Said You Had a Beautiful Body...
- Web Standards in Dreamweaver Part 3
- Web Standards in Dreamweaver, Part 2
- Web Forms
- Making Lists Using XHTML
- Web Standards in Dreamweaver, Part 1

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials