phpstudy Project Actual Warfare - Message Board (Detailed)

follow PHP Chinese Network Learn to make message boards...

Previously, I blogged on csdn about a simple operation of phpstudy. Click here to enter
During the epidemic, we have to pick up what we missed at home. Next, I will add more to what we haven't written before.

5. Creation of PHP Display List File

1. Create a PHP file (named list.php)
2. Write to the file

<!DOCTYPE html>
	<meta charset="utf-8">	
	<title>Message Board</title>
	<?php include("conn.php"); ?>
 	<link rel="stylesheet" type="text/css" href="css.css">
 	<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#a9a9a9">
   		$sql="select * from message ORDER BY id DESC";
   	<tr bgcolor="#eff3f">
   		<td>Title:<?php echo $row['title']; ?>
   		<font color="red">User:<?php echo $row['user'];?>
  	<tr bgcolor="#ffffff">
   		<td>Publish content:<?php echo $row['content']; ?></td>
  	<tr bgcolor="#ffffff">
   		<td align="right">Time:<?php echo $row['lastdate']; ?></td>
  	<?php } ?>
   	<tr bgcolor="#228b22">
   		<td><div align="right">
   	<a href="add.html">Return message</a>

3. Save list.php. Save it in the WWW folder as well, and the PHP display file on this page was created successfully.
4. Open http://localhost/bbs/list.php from your browser to view the message information.

The message message message is displayed as follows: (This happens because I did not fill in the title when I created the message, which will be checked for errors later)

6. Creation of PHP Delete Message File

1. Create a PHP file (named del.php)
2. Write the following to the file.

$query="delete from message WHERE id=".$id;
echo "<script>";
echo "window.location.on.href='$url";
echo "</script>";

3. Save it in the WWW folder as well.
4. Add the following to the list.php file and save it: (that is, delete the line)

5. Open http://localhost/bbs/list.php from your browser and delete your message by clicking Delete.

When you click Delete, the web address changes as follows.

I think there is a bug in the case where it can't go back to the previous page, so I'll make some improvements later when the effect is added.

7. Validation of data validity using js in PHP message board

1. This step does not need to create a new file, it can be done directly in add.html.
2. Add the following to the head tag in add.html:

<script type="text/javascript">
  function CheckPost(){
   if (myform.user.value=="") {
    alert("Please fill in your user name");
    return false;
    alert("Title content cannot be less than five characters");
    return false;
    alert("Content cannot be empty");
    return false;

Below the body tag is the following:

3. Open http://localhost/bbs/add.html from your browser to see the effect.

So far, php's simple battle with phpstudy - message board is complete.
This little battle is shared in the following files:

My WWW folder is located in the following location:

I have a word to say about this small battle:

  1. In the new version of phpstudy, some can't use mysql_xxx, you must use mysqli_xxx, and the code I wrote applies to the new version of phpstudy.
  2. The difference between mysql and mysqli can be Baidu by itself.
  3. This is a simple php introductory hands-on tutorial that you can add to your page to make it a nice message board.
  4. If there are any errors, I hope you can correct them (I also have a small white si).

That's it~

23 original articles published, 0 praised, 1820 visits
Private letter follow

Tags: PHP SQL network Javascript

Posted on Fri, 31 Jan 2020 20:28:08 -0800 by saito