I used to write a Ten Days Society ASP. I have learned what asp.net for ten days. Now I think about writing a PHP again, it is more comparable. PHP debugging method I don't say it here, many articles outside have introduced, and there are many different combinations. I am temporary here to use Apache Web Server and My SQL as a web server and database, a program under php-4.3.3. Of course, you have to construct and access to view the database phpMyAdmin is essential. As for the form design, I don't want to say more here, I have already introduced in "Ten Days Society ASP". Let's take a brief introduction to the grammar of PHP. 1. Embedded method: similar to the "<%, php may be PHP or , End symbol is?>, Of course you can also specify yourself. 2, reference file: There are two ways to reference files: Require and include. The method of use of Requires such as Require ("MyRequirefile.php"); This function is usually placed in the forefront of the PHP program, and the PHP program will read the files introduced by Require before execution, so that it becomes a part of the PHP program page. Commonly used functions, or this method can introduce it into a web page. Include use method such as include ("Myincludefile.php"); This function is typically placed in the processing section of the process control. The PHP program page reads in when reading the file. This way, the process can be simplified when the program is executed. 3, Note Method: PHP Echo "This is the first example ./n"; // This example is a C syntax Note / * This example is multi-line comment * / echo "This is the second example ./N "; echo" This is the third example ./n "; # This example uses UNIX shell syntax notes?> 4. Variable type: $ mystring =" I am string "; $ newline =" wrap / n "; $ INT1 = 38; $ float1 = 1.732; $ float2 = 1.4e 2; $ myarray1 = array (" 子 "," ugly "," 寅 "," "); here to lead two questions, first The PHP variable is started with $ start, the second PHP statement; the end, the ASP programmer may not be adapted. These two omissions are also most errors in the program. 5, operation symbol: Mathematical operation: Symbolic meaning addition operation - subtraction operation * Multiplication / division operation% Take the feasibility accumulation - Decreasing string operation: The operation symbol is only one, that is, the English. It can connect a string to a merged string. Similar to ASP & <$ a = "PHP 4"; $ b = "powerful"; Echo $ a. $ B;?> Here is two problems, first of all PHP output statements are echo, second similar <% = Variable%>, PHP can also be = Variable?>.
Logic operation: symbolic meaning
";}?> The second is except for IF, plus ELSE conditions, can be explained" If a certain How to deal with, otherwise how to solve ". Syntax if (expr) {statement1} else {statement2} example: The above example is modified to more complete processing. Since there is only one line of execution, therefore do not add Parental brackets. Php if ($ state == 1) {echo "haha"; echo "
";} else {echo "huh"; echo "
";}?> The third is The recursive IFEELSE cycle is usually used in a variety of decision judgments. It takes several IF..EELSE to merge usage. Directly look at the example below PHP IF ($ A> $ b) {echo " A ratio B ";} elseif ($ a == $ b) {echo" a equal to B ";} else {echo" a bit ";}?> The above example only uses two IF..EELSE cycles To compare two variables of A and B. Don't use this recursive IFEELSE cycle, please use it, because too many layers are easy to make the design logic, or raise braces, etc., It will cause the program to have an inexplicable problem. 2, the for loop is only one, there is no change, its syntax is as follows for for (expr1; expr2; expr3) {statement} in the initial value of the EXPR1. EXPR2 is the condition of judgment. It is usually used as a condition for judging using logical operators.
EXPR3 is used to perform some of the STATEMENT to change the condition, for the next loop judgment, such as plus one .. and so on. And Statement is part of the eligible execution section. If the program only has a line, you can omit the braces {}. The following example is an example written by for loop. PHP for ($ I = 1; $ I ";}?> 3, switch cycle, usually handled Compound conditions judge, each sub-condition, is a Case instruction section. In practice, if many similar IF instructions can be used, it can be integrated into a Switch loop. Syntax Switch (expr) {Case EXPR1: Statement1; Break; Case EXPR2: STATEMENT2; Break; default: statementn; break;} The expr condition is usually the variable name. The exprn after CASE usually represents a variable value. After the colon, the part to be performed in accordance with this condition. Note To use the BREAK jump from the loop. PHP Switch (Date ("D")) {CASE "MON": echo "Today"; Break; Case "Tue": echo "Tuesday" Today; Break; Case "WED": echo "Today Wednesday" Break; Case "THU": echo "Today Thursday"; Break; Case "Fri": Echo "Friday Today"; Break; Default: Echo "Today's holiday"; Break;}?> Here you need to pay attention to Break; I miss it, default, omitted is ok. Obviously, the above example is very troublesome with an IF cycle. Of course, when designing, the maximum condition in which the chance is maximized is placed in the forefront, and the conditions that appear are placed at the end, and the execution efficiency of the program can be added. The above example is the same as the chance to occur every day, so it is not necessary to pay attention to the order of conditions. Today, I said that the database is used to say tomorrow. Day 3 Learning Purpose: Learn to build a database in ASP, if you are an Access database you can open Access to edit the MDB file, if you are SQL Server, you can open the Enterprise Manager to edit the SQL Server database, but in PHP, My SQL The command line editor may make the beginners feel very troublesome, don't tighten, you download a phpMyAdmin installation, and then build an editing database can rely on it. Let's talk about it. After entering phpMyAdmin, we first need to create a database, and Language (*) Select Chinese Simplified, then create a new database on the left here to fill in the database name here, click Create. Then select the database already created in the drop-down menu on the left drop. Create a new table below in the database Shop: Name: Field number: Fill in the table name and substantially you think (not enough or more, you can add or default later), press execution. Then you can start building a table.
The first column is the name of the field; the second column selection field type: We are commonly used: 1) varchar, text type 2) int, integer type 3) Float, floating point number 4) Date, date 5) Everyone may ask, where is the ID added? This can be selected as long as the int type is selected. After the establishment of the table, you can see the table created on the left. You can: 1) Press the structure on the right: View Modify Table Structure 2) Press the browsing on the right: View the data in the table 3) Press SQL on the right : Run SQL Statement 4) Press the insert: Insert a row of records 5) Press the empty empty: Remove all records in the table: Press the delete of the right: Delete the table still has a very important function to import and export, when we When the machine is doing the program and the database, there is also a local image on the server. If it is an ASP Access simple, you can upload the MDB file directly, if it is SQL Server, you can also connect the remote server for import. So in My SQL you can export all SQL statements, to the phpMyAdmin of the remote server, then press SQL after creating the database, split all the SQL statements generated by the resulting level you just copied. Today, I said that the database operation will continue tomorrow. Day 4 Learning Purpose: Learn to connect to the database PHP is simply a library, rich functions make PHP's certain places quite simple. It is recommended that Down a PHP function manual, the total use. I will talk about connecting the MySQL database here. 1, mysql_connect Opens the MySQL server connection. Syntax: int mysql_connect (String [Hostname], String [username], string [password]); return value: Integer this function establishs the connection with the MySQL server. All of these parameters can be omitted. When using this function but does not add any parameters, the default value of the parameter hostname is localhost, the default value of the parameter username is the owner of the PHP execution itine, the parameter password is an empty string (ie there is no password). The parameter hostname can be reached with the port number, which represents which port is connected to mySQL. Of course, when using the database, use mysql_close () to turn off the connection to save resources. 2, MySQL_SELECT_DB Select a database. Syntax: int mysql_select_db (string database_name, int [link_identifier]); Return Value: Integer This function selects the database in the MySQL server for later data query job (QUERY) processing. Successfully returns true, returns false. The easiest example is: $ conn = mysql_connect ("127.0.0.1", "" "; mysql_select_db (" shop "); Connect MY SQL Database, open the SHOP database. In practical applications should be enhanced. Today, I said here, I will talk about the database reading tomorrow. Transfer from: Dynamic Network Production Guide Www.knowsky.com Day 5 Learning Purpose: Learn to read the data first look at two functions: 1, mysql_query sends a query string.
Syntax: int mysql_query (string query, int [link_identifier]); return value: Integer This function sends a Query string for mysql to do related processing or execution. If you do not specify a link_identifier parameter, the program automatically looks for the recently opened ID. When the Query query string is Update, Insert, and DELETE, the return may be true or false; the query string is SELECT that returns a new ID value, when returning false, not performing success but no return value, but The string of the query has an error. 2, MySQL_FETCH_Object Returns class information. Syntax: Object mysql_fetch_object (int result, int [result_typ]); return value: The class function is used to remove the query result result in the class variable. If Result is not available, return false values. Look at a simple example: $ Exec = "Select * from user"; $ results = mysql_query ($ exec); while ($ RS = mysql_fetch_object) {echo "Username:". $ R-> username "
";}?> Of course, there is a field in the table User, which is similar to the <% exec = "select * from user" set RS = Server.createObject ("adoDb.recordset") similar to the ASP. RS.Open Exec, Conn, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 12, "Username:" & RS ("UserName") & "
" rs.movenext loop%> Of course, first to connect to the database, generally we need_once (' Conn.php '); and Conn.php is the code that connects the database in the last time. A small two commands can complete the job of reading data, today, here, here, the next time the data is added to delete modifications.
Sixth Day Learning Purpose: Learn to add deleted data mysql_query ($ exec); single this statement can perform all the operations, different is $ exec = "Insert Into Tablename (item1, item2) Values ('". $ _ post [' Item1 ']."', ". $ _ post ['Item1'].") "; deletion: $ exec =" delete from tablename where ... "; Modify: $ exec = "Update Tablename Set Item1 = '". $ _ post [' Item1 ']. "' Where ..."; talking here, let's talk about the form and PHP variable delivery, if one of the forms in the form form is submitted by POST, then process the form file to get the variable value with $ _POST ['ITEM1'], which is the same as GET, is $ _GET ['ITEM1'] is not Very simple? But usually $ EXEC will have a problem, as you may be your SQL statement, you will miss. Connect, or 'to enclose the character field. We can comment Mysql_Query ($ exec); the statement uses ECHO $ exec; instead to output $ EXEC to check the correctness. If you still don't know what is wrong with $ exec, you can copy this SQL statement to phpMyAdmin to see its error message. It is also important to note that we don't use some sensitive strings as a field name, otherwise it is likely to have problems, such as Date what. Naming of variables, naming of fields Sometimes sometimes is a benefit of yourself, beginners do not ignore their importance. Today, I will say this, everyone can DOWN a reference manual for SQL statement, and then study. Continue to say session tomorrow. Day 7 Learning Purpose: A lot of the use of Session using session, and the most used is the inter-page variable transmission. Start in the page We want session_start (); turn on the session; then you can use the session variable, for example, you want to assign the value is: $ _ session ['item'] = "item1"; to get the value is $ item1 = $ _ session ['ITEM ']; It is simple. Here we may use some functions, such as judgment is empty, you can write: Empty ($ _ session ['inum']) Returns true or false. Let's take a look at us to see if a login program is correct.
The login form is this: login.php