当用户点击提交按钮时,如何生成带有内容的动态html网页?

时间:2017-05-09 07:21:13

标签: php html

我正在开展一个项目,用户必须通过填写表格来提问。我的问题是,当用户填写表格并提出问题时,php会自动生成html网页。例如,如果用户询问什么是stackoverflow,那么url就像localhost / what-is-stackoverflow,通过单击此链接,此链接显示用户填写的其他内容。 这是我的代码

<?php include("header.php");
require("dbconnect.php");
if(isset($_POST['post'])){

$user_email = $_POST['user_email'];
$user_name =  $_POST['user_name'];
$question_title = $_POST['question_title'];
$question_body = $_POST['question_body'];
$question_title = htmlentities($question_title);
$question_body = htmlentities($question_body);
$insert_question = mysqli_query($con,"insert into questions values('','".$user_email."','".$user_name."','".$question_title."','".$question_body."','".php_slug($question_title)."')");
}

function php_slug($question_title)
{
$slug = preg_replace('/[^a-z0-9-]+/','-' , strtolower($question_title));
return $slug;

}



?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="css/styles.css" rel="stylesheet" type="text/css">
<link href="favicon.ico" rel="shortcut icon" type="img/ico">
</head>
<body>

<div class="container">
<div class="col-lg-7  " >
<div class="form-group ">

<form name="submit_question" action="" method="post">
<label for="user_email" class="control-label " > Enter Your Email Address We Will Mail You Answer </label>

<input type="email" class="form-control" name="user_email" placeholder="Enter Your Email We Will Mail You Answer Of Your Question"  required/>
<br >
<label for="user_name" class="control-label " > Enter Your Name </label>

<input type="text" class="form-control" name="user_name" placeholder="Enter Your Name"  required/>
<br >
<label for="question_title" class="control-label " > Enter Your Question Subject </label>
<input type="text" class="form-control" name="question_title" placeholder="Enter Question Subject"  required/>
<br >
<label for="question_body" class="control-label " > Question Body </label>
<textarea class="form-control pull-middle" rows="20" placeholder="Enter Post Content" name="question_body" required/> </textarea>
<div class="btn btn-group  pull-right">
<br> 
<br> 
<button type="submit" class="btn btn-primary" name="post"> 
<span class="glyphicon glyphicon-plus"></span> Submit Question 

</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
<script src="js/bootstrap.js" > </script>
<?php include("footer.php");?>
</body>

2 个答案:

答案 0 :(得分:0)

我认为

1. You have to post the all content in your <form action=""> page.
2. Get that all data in variables then replace all special characters like space, ? etc from question with '-'.
3. the create url with this updated question with the url parameters like name, email

    $url=localhost/what-is-stackoverflow?email=email@gmail.com&name=abc

4. use .htaccess file to rewrite url 

RewriteRule ^(a-zA-z)$ filename [L]

5. redirect to that url with url parameters.

    redirect($url,'refresh');

6.on that page get all url parameters.

答案 1 :(得分:0)

$myFile = $questiontitle.".html"; // or .php $fh = fopen($myFile, 'w'); // or die("error"); $stringData = "<html><head><title>".$questionbody."</title></head><body></body></html>"; fwrite($fh, $stringData);

您可以创建html文件并通过php

以编程方式添加html内容