首先,您的PHP或HTML页面应该生成一个用户可以与之交互的表单.最多
简单的形式它是这样的:
这将为您的用户提供一个简单的表单,其中包含单个输入字段和“保存”按钮.点击后
内容的“保存”按钮将使用POST方法发送到您的“yourscript.php”.
yourscript.php应该实现以下内容:
>接受并处理表单中的输入.
>连接到MySQL数据库.
>存储到数据库中.
以最简单的形式,这将是:
Process and store// Check that user sent some data to begin with.
if (isset($_REQUEST['yourfield'])) {
/* Sanitize input. Trust *nothing* sent by the client.
* When possible use whitelisting, only allow characters that you know
* are needed. If username must contain only alphanumeric characters,
* without puntation, then you should not accept anything else.
* For more details, see: https://stackoverflow.com/a/10094315
*/
$yourfield=preg_replace('/[^a-zA-Z0-9\ ]/','',$_REQUEST['yourfield']);
/* Escape your input: use html