Free message Ben Php+mysql write a simple message This example code

Source: Internet
Author: User
guestbook.php:



<title></title>













Senior Class <6> Message Book














Include ("Connect.rec");
$QH =mysql_query ("Select COUNT (*) as rcnt from Guestbook");
$data =mysql_fetch_array ($QH);
$NR = $data ["rcnt"];
Determines whether the offset parameter is passed to the script, and if not, uses the default value of 0
if (empty ($offset))
{
$offset = 0;
}
Query results (Here are 20 per page, but you can completely change it yourself)
$result =mysql_query ("SELECT * from Guestbook ORDER BY time Desc LIMIT $offset, 5");
$result =mysql_query ("SELECT * from Guestbook LIMIT $offset, 5");
Shows the 5 records returned
while ($data =mysql_fetch_array ($result))
{
printf ("Name:%s
", $data [" name "]);
printf ("email:%s
", $data [" Mail "]);
printf ("Personal page:%s
", $data [" url "]);
printf ("From:%s
", $data [" IP "]);
printf ("Message Time:%s
", $data [" Time "]);
printf ("Subject:%s
", $data [" title "]);
printf ("Content:%s
", $data [" ly "]);
printf (" ");
}
Next, write a link to another page
if ($offset)//If the offset is 0, the previous page link is not displayed
{
$preoffset = $offset-5;
Print "previous page n";
}
Calculate the total number of pages required
$pages =ceil ($NR/5); $pages variable now contains the required number of pages
for ($i =1; $i <= $pages; $i + +)
{
$newoffset =5* $i-5;
print "$i n";
}
Check if it is the last page
$next = $offset +5;
if ($next < $NR)
{
Print "next page n";
}
printf ("Back")
?>





ly.php:
Include ("Connect.rec");
$name = $T 1;
$mail = $T 2;
$url = $T 3;
$title = $T 4;
$time = Date ("Y-m-j h:i:s");
$ip = getenv ("REMOTE_ADDR");
$ly = $S 1;
$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 success! ");
printf ("");
}
Else
{
Echo ("Message failed!") ");
printf ("return");
}
?>

The above describes the free message of this php+mysql write a simple message This example code, including the content of the free message, I hope that the PHP tutorial interested in a friend helpful.

  • 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.