在PHP和MySql中为每个ID创建一个注释框 [英] Create a comment box in PHP and MySql for each ID

查看:104
本文介绍了在PHP和MySql中为每个ID创建一个注释框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个网站,人们可以对我拍摄的所有照片发表评论。
每张照片都有自己的网页; Id = 1 Id = 2等。

I am doing a site where people can leave comments on all the pictures I have photographed. Every photo has it’s own page; Id=1 Id=2 etc.

我想要一个评论框,我的访问者可以添加和查看已发布的其他评论。

I would like a comment box where my visitors can add and see other comments already posted.

任何提示或示例代码都将非常感激。

Any tips or example code would be very appreciated.

推荐答案

我假设你有一些关于MySQL,PHP和使用MySQL与PHP的基本知识。你已经定义了数据库表吗?

I assume you have some basic knowledge about MySQL, PHP and using MySQL with PHP. Do you already have a database table defined?

无论如何,对于注释,假设它们可以匿名编写,我将创建一个表 / code> as as:

Anyway, for the comments, assuming they can be written anonymously, I would create a table comment as such:

`id` INT AUTO_INCREMENT,
`image_id` INT NOT NULL,
`content` VARCHAR(1024) NOT NULL,
`timestamp` TIMESTAMP NOT NULL DEFAULT NOW(),
PRIMARY KEY (`id`)

创建一个简单的表单,将您发送到一个php页面,将输入的数据插入数据库。

Create a simple form that will send you to a php page which inserts the entered data into the database.

<form name="comment" action="addcomment.php" method="post">
  <input type="hidden" id="image_id" value="$image_id" />
  <textarea id="content"></textarea>
  <input type="submit" />
</form>

$ image_id

addcomment.php 中的数据库条目应该包含类似于此的内容:

The database entry in addcomment.php should contain something similar to this:

<?php
$image_id = $_POST['image_id'];
$content = $_POST['content'];

mysql_query('INSERT INTO `comment` (`image_id`, `content`) VALUES('.$image_id.', "'.$content.'");
?>

注意:这些只是裸骨提示,都会看起来不好和不安全,帮助您开始使用... ...

Note: those are only bare bone hints that will both look bad and be insecure, but they should help you getting started with this...

这篇关于在PHP和MySql中为每个ID创建一个注释框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆