MySQL Database Handling in PHP

Written by John L


Continued from page 1

The @ operator is used to suppress any error messages that mysql_connect() and mysql_select_db() functions may produce if an error occurred. The die() function is used to endrepparttar script execution and display a custom error message.

Executing SQL Statements against a MySQL database

Oncerepparttar 105568 connection and database selection is successfully performed,repparttar 105569 PHP script can now proceed to operate onrepparttar 105570 database using standard SQL statements. The mysql_query() function is used for executing standard SQL statements againstrepparttar 105571 database. Inrepparttar 105572 following example,repparttar 105573 PHP script queries a table called tbl_login inrepparttar 105574 previously selected database to determine if a username/password pair provided byrepparttar 105575 user is valid.

Assumption: The tbl_login table has 3 columns named login, password, last_logged_in. The last_logged_in column storesrepparttar 105576 time thatrepparttar 105577 user last logged intorepparttar 105578 system.

// The $username and $passwd variable should rightly be set byrepparttar 105579 login form // throughrepparttar 105580 POST method. Forrepparttar 105581 purpose of this example, we’re manually coding it. $username = “john”; $passwd = “mypassword”;

// We generate a SELECT SQL statement for execution. $sql="SELECT * FROM tbl_login WHERE login = '".$username."' AND password = '".$passwd."'";

// Executerepparttar 105582 SQL statement againstrepparttar 105583 currently selected database. // The results will be stored inrepparttar 105584 $r variable. $r = mysql_query($sql);

// Afterrepparttar 105585 mysql_query() command executes,repparttar 105586 $r variable is examined to // determine ofrepparttar 105587 mysql_query() was successfully executed. if(!$r) { $err=mysql_error(); print $err; exit(); }

// If everything went well, check ifrepparttar 105588 query returned a result – i.e. ifrepparttar 105589 username/password // pair was found inrepparttar 105590 database. The mysql_affected_rows() function is used for this purpose. // mysql_affected_rows() will returnrepparttar 105591 number of rows inrepparttar 105592 database table that was affected // byrepparttar 105593 last query if(mysql_affected_rows()==0){ print "Username/password pair is invalid. Please try again."; } else {

// If successful, read outrepparttar 105594 last logged in time into a $last variable for display torepparttar 105595 user $row=mysql_fetch_array($r); $last=$row["last_logged_in"]; print “Login successful. You last logged in at ”.$last.”.”;

}

The above example demonstrated how a SELECT SQL statement is executed againstrepparttar 105596 selected database. The same method is used to execute other SQL statements (e.g. UPDATE, INSERT, DELETE, etc.) againstrepparttar 105597 database usingrepparttar 105598 mysql_query() and mysql_affected_rows() functions.

This PHP scripting article is written by John L. John L is the Webmaster of The Ultimate BMW Blog! (http://www.bimmercenter.com).

The Ultimate BMW Blog!


XML Promises and challenges

Written by Ror Sabo


Continued from page 1

Microsoft XML Validation Tool checks that an XML file is well formed.

XML Spy is a powerful XML editor.

XMetaL is an advanced, simple-to-deploy XML authoring tool that delivers an unprecedented ease of use.

More XML Tools >>

XML Free Tutorial: A lot of free tutorial can be found on different ways XML can be used.

2-XML Syntax

   The simple and very strict syntax rules of XML.

3-XML Elements

   XML Elements, relationships, content and naming rules.

4-XML Attributes

   How XML attributes can be used to describe elements, or to provide additional information about

   elements.

5-XML Validation

   The difference between a Well Formed and a Valid XML document and how a DTD is used to define

   the XML document.

6-XML support in Netscape and Explorer

   Aboutrepparttar 105567 support for XML inrepparttar 105568 two most famous browsers.

7-Viewing XML in Internet Explorer

   How to use Internet Explorer to view an XML file.

8-Displaying XML with CSS

   How to use Internet Explorer and CSS to display an XML file.

9-Displaying XML with XSL

   How to use Internet Explorer and XSL to display an XML file.

10-XML embedded in HTML

   How to embed XML inside HTML documents.

11-The Microsoft XML Parser

   How to userepparttar 105569 Microsoft XML parser to open and manipulate XML documents.

12-XML in Real Life

   This is where we take a look at some real life use of XML.

13-XML Namespaces

   How to avoid element name conflicts using XML namespaces.

14-XML CDATA

   How to tell an XML parser not to parserepparttar 105570 text.

15-XML Encoding

   How to encode your XML documents.

16-XML Server

   How to generate XML onrepparttar 105571 server.

17-XML Applications

   How you can use IE to navigate an XML file and how to create a complete XML application.

18-XML HTTP Requests

   How to request XML from a server using HTTP.

19-Behaviors for HTML and XML

   Howrepparttar 105572 new CSS behavior selector can be used to create dynamic content.

20-XML Technologies

   XML technologies that are important torepparttar 105573 understanding and development of XML applications.



Softlookup.com Your free online Resources for software and Hardware Drivers in addition to Free online tutorial


    <Back to Page 1
 
ImproveHomeLife.com © 2005
Terms of Use