Message book I wrote using php + mysql _ php Basics

Source: Internet
Author: User
Tags php basics
The message book guestbook. php I wrote using php + mysql:



















High school <6> class message book














Include ("connect. rec ");

$ Qh = mysql_query ("select count (*) AS rcnt FROM guestbook ");

$ Data = mysql_fetch_array ($ qh );

$ Nr = $ data ["rcnt"];

// Determine whether the offset parameter is passed to the script. if not, use the default value 0.

If (empty ($ offset ))

{

$ Offset = 0;

}
// Query result (20 entries per page, but you can change it by yourself)

// $ Result = mysql_query ("SELECT * from guestbook order by time desc LIMIT $ offset, 5 ");
$ Result = mysql_query ("SELECT * from guestbook LIMIT $ offset, 5 ");

// Display the returned five records

While ($ data = mysql_fetch_array ($ result ))
{
Printf ("name: % s
", $ Data [" name "]);
Printf ("EMAIL: % s
", $ Data [" mail "]);
Printf ("personal homepage: % s
", $ Data [" url "]);
Printf ("From: % s
", $ Data [" ip "]);
Printf ("Message Time: % s
", $ Data [" time "]);
Printf ("topic: % s
", $ Data [" title "]);
Printf ("content: % s
", $ Data [" ly "]);
Printf (" ");
}

// Next, write the link to another page

If ($ offset) // if the offset is 0, the link to the previous page is not displayed.
{
$ Preoffset = $ offset-5;
Print "previous page n ";
}

// Calculate the total number of required pages

$ Pages = ceil ($ nr/5); // $ pages variable now contains the required page number

For ($ I = 1; $ I <= $ pages; $ I ++)

{

$ Newoffset = 5 * $ I-5;

Print "$ I n ";

}

// Check whether it is the last page
$ Next = $ offset + 5;
If ($ next <$ nr)
{
Print "next n ";
}
Printf ("return ")
?>






Ly. php:

Include ("connect. rec ");
$ Name = $ T1;
$ Mail = $ T2;
$ Url = $ T3;
$ Title = $ T4;
$ Time = date ("Y-m-j H: I: s ");
$ Ip = getenv ("REMOTE_ADDR ");
$ Ly = $ S1;

$ Result = mysql_query ("insert into guestbook (name, mail, url, ip, time, title, ly) values ('$ name',' $ mail ', '$ url',' $ IP', '$ time',' $ title', '$ ly ')");
If ($ result = 1)
{
Echo ("message successful! ");
Printf ("

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.