<meta http-equiv= "Content-type" content= "text/html; charset=gb2312"/>
<script language= "JavaScript Tutorial"
check111cnnet ()
{
var keyword = myfm.keyword.value;
if (keyword = = ")
{
alert (' www.111cn.net prompts you: Please enter the content to query ');
return false;
}
}
</script>
<body>
<form id= "myFM" name= "myFM" method= "POST" action= "" >
<label>
Enter Query keywords:
<input type= "text" name= "keyword"/>
</label>
<label>
<input type= "Submit" name= "Submit" value= "submitted" onclick= "return Check111cnnet ();"/>
</label>
</form>
</body>
<?php
Create a Database Tutorial connection
MySQL tutorial _connect (' localhost ', ' 111cn.net ', ' www.111cn.net ');
mysql_select_db (' www.111cn.net ');//Database selection
mysql_query (' Set names "GBK");
Progress Query Operations
if ($_post)
{
$keyword = $_post[' keyword '];
$sql = "SELECT * from search where title is like '% $key word% ' Limit 0,10 ';
$query = mysql_query ($sql) or Die ("www.111cn.net prompts you: query is wrong");
if (mysql_num_rows ($query))
{
while ($rs = mysql_fetch_array ($query)
{
echo $rs [' title '];
}
else &NBSP
{
echo ' no content to look for ';
}
/*
Data table structure
CREATE TABLE ' 111cnNet '. ' Test ' (
' ID ' INT (8) not NULL auto_increment,
' Title ' CHAR ($) NULL,
' Content ' TEXT NULL,
PRIMARY KEY (' id ')
) ENGINE
*/
function parsing
Mysql_connect//database connection has three parameters for the database server name, username, password
There are two mysql_select_db//parameters, the second is optional, the first database name, and the second database connection $connwww.111cn.net
mysql_query (' Set names "GBK"); This sentence is more important, is to set the reading of the database content encoding, this sentence to be set up with the document editing consistent, otherwise may appear garbled.
mysql_query//Data query, there are two parameters, the first must, for SQL query statement.
Mysql_num_rows//Statistics mysql_query query record how many bars, return to int type
Mysql_fetch_array//Read the current Recordset one record to save to the array.
$_post
If Else
While
Original site reprint must indicate the source or the source of responsibility http://www.111cn.net/phper/php.html
?>