Web page (read data from database in PHP)

Source: Internet
Author: User
Tags php database

---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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.