php页面自动生成,用户通过PHP填写表单后如何自动生成页面?

假设我有一个包含两个输入字段,标题和注释的表单.在用户填写两个字段并提交数据后,将自动创建一个页面,其中包含用户键入的标题和注释,位于根目录中的文件夹中,例如www.root.com/page/将包含自动生成的页面.

更新:

我希望将表单数据发送到SQL表行,并将自动生成的页面的url与标题和注释放在同一个SQL行中.

我如何通过PHP完成此操作?

解决方法:

//Template for basic page

$template = <<

EOD;

//handle the posted form

if(isset($_POST['title'])&&isset($_POST['comment'])){

//replace the areas of the template with the posted values

$page = str_replace('',htmlentities($_POST['title']),$template);

$page = str_replace('',htmlentities($_POST['comment']),$page);

//create a name for the new page

$pagename = md5($_POST['title']).'.html';

//db connect & select

$db=mysql_connect('localhost','user','pass');

mysql_select_db('yourdb');

//check if page already exists

$result = mysql_query('SELECT pagename from yourtable WHERE url="'.mysql_real_escape_string($pagename).'"');

if(mysql_num_rows($result)>=1){

$notice = '

Page already created ./pages/'.$pagename.'

';

}else{

//inset new page into db

mysql_query('INSERT into yourtable (`id`,`title`,`comment`,`url`)VALUES("",

"'.mysql_real_escape_string(htmlentities($_POST['title'])).'",

"'.mysql_real_escape_string(htmlentities($_POST['comment'])).'",

"'.$pagename.'")');

//put the created content to file

file_put_contents('./pages/'.$pagename,$page);

//make a notice to show the user

$notice = '

New Page created ./pages/'.$pagename.'

';

}

}

?>

Make page example

//if the notice is set then display it

if(isset($notice)){echo $notice;} ?>

Title:

Comment:

标签:html,php,forms,directory

来源: https://codeday.me/bug/20190826/1735384.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值