---restore content starts---
These days are in small projects, do is to know the Web page, I think the most difficult place to know the page in the data read, you can use json.js; you can also use PHP database to get data, below is some of the code I wrote to read database data in PHP, first home main content read, Two parts conn.php and zhihu_exec.php; registration has three parts conn.php,zhuce_add.php,zhuce.insert.php; login has two parts login.php,login.exec.php;
Here is the specific code:
One: Home
1. Call the database and read the data in the database conn.php
<?php
$connMysql_connect' localhost '' Root '‘‘Or Die' Connection error:
‘Mysql_error@mysql_select_db' Zhihu '$connOr Die "Error selecting database:
' mysql_error @mysql_query "set names UTF8 ' or die " Character encoding selection error:
' mysql_error $sql ' $result = mysql_query ( $sql)
while ( $row mysql_fetch_assoc $result)
?>,
... Omit PHP code
<?php
}
?>
2.session Saving Data
<?php
Session_Start;
Require‘.. /conn/conn.php ';
IfIsset$_post[' title ']) {
$title =$_post[' title '];
$sql ="Select ' title ' From ' Index ' WHERE title= ' $title
$result =mysql_query ( $sql);
$user =array{};
while ( $row = MYSQL_FETCH_ASSOC ( $result));
$user = $row;
if ( $user); 0) {
$_session[' user ']=$user;
$user' title '];
}else{
echo 0;
}
< Span style= "color: #660000;" > ?>
II: Registration
//Connect to read database First conn.php
<?php
Session_Start;
Require' zhuce_add.php ';
if (isset ($_post[ $userName = $_post[ ' UserName '];
$n = $userName;
if ( $n; 0) {
echo $n
}else{
Span style= "color: #000080; Font-weight:bold; " >echo 0
}
?>
//zhuce.add.php;
/span>
<?php
function ($userName,$password,$tel) {
$conn =Mysql_connect (' localhost ',' Root ',‘‘)@mysql_select_db' Zhihu '$connOr Die' Database error 'Mysql_error;
@mysql_query (' Set names UTF8 ');
$sql = $userName , $password , $tel ; @mysql_query ( $sql );
$n =mysql_affected_rows ();
mysql_close ( $conn);
return $n;
}
function Readajax($userName) {
$conn =Mysql_connect (' localhost ',' Root ',‘‘)Or Die' Connection to MySQL error: 'Mysql_error;
mysql_select_db (' Zhihu ',$conn);
mysql_query (' Set names UTF8 ');
$sql =The SelectCount(*) from ' login ' WHERE userName = ' $userName ";
$result = mysql_query ( $sql) or die "database statement execution error: '
---restore content ends---
Web page (read data from database in PHP)