整个代码如下所示:我所要做的就是保存通过from提交的用户数据的整个页面。
基本上,用户在表单中输入一组详细信息,然后根据输入生成页面,并将其保存为xyz.html。
以我的方式可以做到吗?还是出了什么问题?
或者请告诉我基于用户表单输入创建页面的最佳方法是什么.
我只是在一个php变量中构建了一个完整的HTML页面代码,结果被搞糊涂了。
<?php require_once('Connections/conn.php'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var text_max = 200;
$('#textarea_count').html(text_max + ' characters remaining');
$('#comment').keyup(function() {
var text_length = $('#comment').val().length;
var text_remaining = text_max - text_length;
$('#textarea_count').html(text_remaining + ' characters remaining');
});
});
$(document).ready(function() {
var text_max = 200;
$('#textarea_count1').html(text_max + ' characters remaining');
$('#comment1').keyup(function() {
var text_length = $('#comment1').val().length;
var text_remaining = text_max - text_length;
$('#textarea_count1').html(text_remaining + ' characters remaining');
});
});
$(document).ready(function() {
var text_max = 600;
$('#textarea_count2').html(text_max + ' characters remaining');
$('#comment2').keyup(function() {
var text_length = $('#comment2').val().length;
var text_remaining = text_max - text_length;
$('#textarea_count2').html(text_remaining + ' characters remaining');
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
var maxField = 10; //Input fields increment limitation
var addButton = $('.add_button'); //Add button selector
var wrapper = $('.field_wrapper'); //Input field wrapper
var fieldHTML = '<div><input type="text" name="field_name[]" value=""/><a href="javascript:void(0);" class="remove_button"><img src="remove-icon.png"/></a></div>'; //New input field html
var x = 1; //Initial field counter is 1
//Once add button is clicked
$(addButton).click(function(){
//Check maximum number of input fields
if(x < maxField){
x++; //Increment field counter
$(wrapper).append(fieldHTML); //Add field html
}
});
//Once remove button is clicked
$(wrapper).on('click', '.remove_button', function(e){
e.preventDefault();
$(this).parent('div').remove(); //Remove field html
x--; //Decrement field counter
});
});
</script>
</head>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO properties (property_name, property_location, property_city, property_rera_id, property_for, property_type, property_status, property_possession, property_configuration, property_builder, property_price_range, property_launch_date) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['property_name'], "text"),
GetSQLValueString($_POST['property_location'], "text"),
GetSQLValueString($_POST['property_city'], "text"),
GetSQLValueString($_POST['property_rera_id'], "text"),
GetSQLValueString($_POST['property_for'], "text"),
GetSQLValueString($_POST['property_type'], "text"),
GetSQLValueString($_POST['property_status'], "text"),
GetSQLValueString($_POST['property_possession'], "text"),
GetSQLValueString($_POST['property_configuration'], "text"),
GetSQLValueString($_POST['property_builder'], "text"),
GetSQLValueString($_POST['property_price_range'], "text"),
GetSQLValueString($_POST['property_launch_date'], "text"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
mkdir("".$_POST['property_builder']."");
mkdir("".$_POST['property_builder']."/".$_POST['property_city']."");
mkdir("".$_POST['property_builder']."/".$_POST['property_city'].""."/".$_POST['property_location']."");
mkdir("".$_POST['property_builder']."/".$_POST['property_city'].""."/".$_POST['property_location'].""."/".$_POST['property_type']);
$file_to_write = $_POST['property_name'].".html";
$content_to_write='
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>'.$_POST['property_name'].' | '.$_POST['property_type'].' '.$_POST['property_location'].'</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<!--[if lt IE 9]><script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script><![endif]-->
</head>
<body>
<div class="page-wrapper">
<header class="main-header">
<div class="header-upper">
<div class="container-fluid clearfix">
<div class="header-inner d-lg-flex align-items-center">
<div class="logo-outer">
<div class="logo"><a href="index.html"><img src="assets/images/logo/logo.png" alt="'.$_POST['property_name'].' Logo" title="'.$_POST['property_name'].' Logo"></a></div>
</div>
<div class="nav-outer clearfix ml-130">
<nav class="main-menu navbar-expand-lg">
<div class="navbar-header clearfix">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse clearfix">
<ul class="navigation clearfix">
<li><a href="index-2.html">Home</a></li>
<li><a href="about.html">about</a></li>
<li><a href="rentals.html">RENTALS</a></li>
<li class="current"><a href="sales.html">sales</a></li>
<li><a href="agent.html">AGENT</a></li>
<li><a href="blog.html">blog</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
</nav>
</div>
<div class="menu-btn ml-lg-auto">
<a href="#" class="theme-btn" data-toggle="modal" data-target="#login">LOGIN</a>
<a href="#" class="ml-25" data-toggle="modal" data-target="#signup">SIGN UP</a>
</div>
</div>
</div>
</div>
</header>
<section class="banner-section">
<div class="container">
<div class="banner-inner text-center">
<h2 class="page-title">'.$_POST['property_name'].'</h2>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index-2.html">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Sales Details</li>
</ol>
</nav>
</div>
</div>
</section>
<section class="rentals-page mt-195 mb-150 rmt-95 rmb-70">
<div class="container">
<h6 class="section-hint">'.$_POST['property_name'].' Details</h6>
<div class="property-heading">
<h2 class="section-title">'.$_POST['property_name'].'</h2>
<span class="rent-sale bg-red">'.$_POST['property_status'].'</span>
<span class="price ml-auto">'.$_POST['property_price_range'].'</span>
</div>
<div class="location-time">
<span class="property-location"><i class="fas fa-map-marker-alt"></i> '.$_POST['property_location'].'</span>
<span class="posted-time">: '.$_POST['property_type'].'</span>
</div>
<hr>
<ul class="info mb-50 font-weight-bold">
<li>Configurations : '.$_POST['property_configuration'].'</li>
<li>Possession : '.$_POST['property_possession'].'</li>
<li>Price Range : '.$_POST['property_price_range'].'</li>
<li>Type : '.$_POST['property_type'].'</li>
</ul>
<div class="row">
<div class="col-lg-8">
<div class="property-details-content">
<div class="property-slider single-item-carousel owl-carousel">
<img src="assets/images/properties/property-slider-1.png" alt="Property Slider">
<img src="assets/images/properties/property-slider-2.png" alt="Property Slider">
<img src="assets/images/properties/property-slider-3.png" alt="Property Slider">
<img src="assets/images/properties/property-slider-4.png" alt="Property Slider">
</div>
<h5 class="mt-55 mb-20">Property Description</h5>
<p>'.$_POST['1stpara'].'</p>
<p>'.$_POST['2ndpara'].'</p>
<p>'.$_POST['3rdpara'].'</p>
<div class="quick-information mt-55 mb-45 clearfix">
</div>
<div class="amenities mb-45 clearfix">
<h5 class="mb-20">Amenities</h5>
<ul>
</ul>
</div>
<h5 class="mb-25">Property Video</h5>
<div class="video-section mb-55">
<a href="https://www.youtube.com/watch?v=xj0qi6-QLPo" class="mfp-iframe video-link">
<i class="flaticon-play-button-1"></i>
<span class="ripple"></span>
</a>
</div>
<div class="floor-plan mb-50">
<h5 class="mb-25">Floor Plan</h5>
<img src="assets/images/properties/floor-plan.png" alt="Floor Plan">
</div>
</div>
</div>
<div class="col-lg-4">
<div class="property-sidebar">
<div class="agent-item">
<div class="agent-thumb">
<img src="assets/images/agent/agent-1.png" alt="Agent Image">
</div>
<div class="agent-data">
<h5>Contact Seller</h5>
</div>
<h6 class="agent-number mb-55">
<span class="num-show">+91 888 . . . . . . </span>
<a href="tel:+918884440963" class="num-hide">+91 888 444 0963 </a>
<button class="num-show"> Show Number</button>
</h6>
<form action="#">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Name" required="">
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email" required="">
</div>
<div class="form-group">
<input type="text" name="number" class="form-control" placeholder="Phone Number" required="">
</div>
<div class="form-group">
<textarea class="form-control" placeholder="Phone Number" required="" rows="6"></textarea>
</div>
<div class="form-group m-0">
<button class="theme-btn">Send Message</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
<div class="modal fade sign" id="login" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span class="flaticon-close" aria-hidden="true"></span>
</button>
<div class="sign-inner">
<form action="#">
<div class="row clearfix">
<div class="col-md-12">
<div class="form-group">
<input type="text" name="username" class="form-control" placeholder="User Name" required>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<input type="password" name="password" class="form-control" placeholder="Password" required>
</div>
</div>
<div class="col-md-12">
<div class="form-group mb-20">
<button class="theme-btn" type="submit">Sign In</button>
</div>
</div>
</div>
</form>
<div class="forgot-have d-flex mb-55">
<span class="forgot">Forgot Password</span>
<span class="have ml-auto">Dont have an account yet ? <a href="#">Sign Up!</a></span>
</div>
<div class="or mb-25"><span>or</span></div>
<div class="signup-by d-flex justify-content-between">
<a href="#" class="bg-blue"><i class="fab fa-facebook-f"></i> <span>Facebook</span></a>
<a href="#" class="bg-light-blue"><i class="fab fa-twitter"></i> <span>Twitter</span></a>
<a href="#" class="bg-red"><i class="fab fa-google"></i> <span>Google</span></a>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade sign" id="signup" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span class="flaticon-close" aria-hidden="true"></span>
</button>
<div class="sign-inner">
<form action="#">
<div class="row clearfix">
<div class="col-md-6">
<div class="form-group">
<input type="text" name="first-name" class="form-control" placeholder="First Name" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="text" name="last-name" class="form-control" placeholder="Last Name" required>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email" required>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<input type="password" name="password" class="form-control" placeholder="Password" required>
</div>
</div>
<div class="col-md-12">
<div class="form-group mb-20">
<button class="theme-btn" type="submit">Sign Up</button>
</div>
</div>
</div>
</form>
<div class="forgot-have d-flex mb-55">
<span class="forgot">Forgot Password</span>
<span class="have ml-auto">Dont have an account yet ? <a href="#">Sign In!</a></span>
</div>
<div class="or mb-25"><span>or</span></div>
<div class="signup-by d-flex justify-content-between">
<a href="#" class="bg-blue"><i class="fab fa-facebook-f"></i> <span>Facebook</span></a>
<a href="#" class="bg-light-blue"><i class="fab fa-twitter"></i> <span>Twitter</span></a>
<a href="#" class="bg-red"><i class="fab fa-google"></i> <span>Google</span></a>
</div>
</div>
</div>
</div>
</div>
<footer class="footer-section bg-white pt-150 pb-100 rpt-100">
<div class="container text-center">
<div class="footer-inner">
<div class="footer-logo mb-25">
<a href="index-2.html"><img src="assets/images/logo/footer-logo.png" alt="Footer Logo"></a>
</div>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.</p>
<div class="social-style-one mt-35">
<a href="#"><i class="fab fa-facebook-f"></i></a>
<a href="#"><i class="fab fa-twitter"></i></a>
<a href="#"><i class="fab fa-google"></i></a>
<a href="#"><i class="fab fa-linkedin-in"></i></a>
</div>
</div>
</div>
</footer>
<div class="copyright pt-35 pb-35">
<div class="container text-center">
<p><a href="../cdn-cgi/l/email-protection.html" class="__cf_email__" data-cfemail="bcffd3ccc5ced5dbd4c8fc8e8c8d85">[email protected]</a> Techoners. All rights reserved</p>
</div>
</div>
</div>
<button class="scroll-top scroll-to-target" data-target="html"><span class="fa fa-angle-up"></span></button>
<script src="assets/js/jquery.min.js" type="60b2dc441219fb3e31fa6c9f-text/javascript"></script>
<script src="assets/js/leaflet.min.js" type="60b2dc441219fb3e31fa6c9f-text/javascript"></script>
<script src="assets/js/jquery-ui.min.js" type="60b2dc441219fb3e31fa6c9f-text/javascript"></script>
<script src="assets/js/bootstrap.min.js" type="60b2dc441219fb3e31fa6c9f-text/javascript"></script>
<script src="assets/js/owl.carousel.min.js" type="60b2dc441219fb3e31fa6c9f-text/javascript"></script>
<script src="assets/js/jquery.nice-select.min.js" type="60b2dc441219fb3e31fa6c9f-text/javascript"></script>
<script src="assets/js/jquery.magnific-popup.min.js" type="60b2dc441219fb3e31fa6c9f-text/javascript"></script>
<script src="assets/js/wow.min.js" type="60b2dc441219fb3e31fa6c9f-text/javascript"></script>
<script src="assets/js/appear.js" type="60b2dc441219fb3e31fa6c9f-text/javascript"></script>
<link rel="shortcut icon" href="assets/images/favicon.png" type="image/x-icon">
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="assets/css/responsive.css">
<script src="assets/js/script.js" type="60b2dc441219fb3e31fa6c9f-text/javascript"></script>
<script src="https://ajax.cloudflare.com/cdn-cgi/scripts/95c75768/cloudflare-static/rocket-loader.min.js" data-cf-settings="60b2dc441219fb3e31fa6c9f-|49" defer=""></script></body>
</html>
';
$amenities = $_POST['amenities'];
$amenitisArr = explode(",", $amenities);
foreach ($amenitisArr as $str) {
$content_to_write += '<li>'.$str.'</li>';
}
$file = fopen("".$_POST['property_builder']."/".$_POST['property_city'].""."/".$_POST['property_location']."/".$_POST['property_type'] . '/' . $file_to_write,"w");
// a different way to write content into
// fwrite($file,"Hello World.");
fwrite($file, $content_to_write);
// closes the file
fclose($file);
}
mysql_select_db($database_conn, $conn);
$query_Recordset1 = "SELECT * FROM properties";
$Recordset1 = mysql_query($query_Recordset1, $conn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Builder Name:</td>
<td><input type="text" name="property_builder" value="" class="form-control" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property Name:</td>
<td><input type="text" name="property_name" value="" class="form-control" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property Location:</td>
<td><input type="text" name="property_location" value="" class="form-control" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property City:</td>
<td><input type="text" name="property_city" class="form-control" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property RERA Id:</td>
<td><input type="text" name="property_rera_id" class="form-control" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property For:</td>
<td><select name="property_for" class="form-control">
<option value="Sale" <?php if (!(strcmp("Sale", ""))) {echo "SELECTED";} ?>>Sale</option>
<option value="New" <?php if (!(strcmp("New", ""))) {echo "SELECTED";} ?>>New</option>
<option value="Re-Sale" <?php if (!(strcmp("Re-Sale", ""))) {echo "SELECTED";} ?>>Re-Sale</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property Type:</td>
<td><select name="property_type" class="form-control">
<option value="Apartment" <?php if (!(strcmp("Apartment", ""))) {echo "SELECTED";} ?>>Apartment</option>
<option value="Villa" <?php if (!(strcmp("Villa", ""))) {echo "SELECTED";} ?>>Villa</option>
<option value="Plot" <?php if (!(strcmp("Plot", ""))) {echo "SELECTED";} ?>>Plot</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property Status:</td>
<td>
<select name="property_status" class="form-control">
<option value="Under-Construction" <?php if (!(strcmp("Under-Construction", ""))) {echo "SELECTED";} ?>>Under-Construction</option>
<option value="Pre-Launch" <?php if (!(strcmp("Pre-Launch", ""))) {echo "SELECTED";} ?>>Pre-Launch</option>
<option value="Read to move in" <?php if (!(strcmp("Read to move in", ""))) {echo "SELECTED";} ?>>Read to move in</option>
</select>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property Possession:</td>
<td><input class="form-control" type="text" name="property_possession" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property Configuration:</td>
<td><input class="form-control" type="text" name="property_configuration" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property Area:</td>
<td><input class="form-control" type="text" name="property_area" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property Price Range:</td>
<td><input class="form-control" type="text" name="property_price_range" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property Launch Date:</td>
<td><input class="form-control" type="text" name="property_launch_date" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property Discription 1st Para:<br /><br />
<div id="textarea_count" class="badge pull-right"></div></td>
<td><textarea class="form-control" name="1stpara" id="comment" rows="5" maxlength="200"></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property Discription 2nd Para:<br /><br />
<div id="textarea_count1" class="badge pull-right"></div></td>
<td><textarea class="form-control" name="2ndpara" id="comment1" rows="5" maxlength="200"></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Property Discription 3rd Para:<br /><br />
<div id="textarea_count2" class="badge pull-right"></div></td>
<td><textarea class="form-control" name="3rdpara" id="comment2" rows="5" maxlength="600"></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Amenities</td>
<td><textarea name="amenities" class="form-control"></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>发布于 2019-11-16 06:14:05
你想要这样的东西,你需要把它放在正确的地方。
$content_to_write = '...
...
<div class="amenities mb-45 clearfix">
<h5 class="mb-20">Amenities</h5>
<ul>
'; // end content
// add <li>
$amenities = $_POST['amenities'];
$amenitisArr = explode(",", $amenities);
// add values to html
foreach ($amenitisArr as $str) {
$content_to_write .= '<li>'.$str.'</li>';
}
// continue in content
$content_to_write .= '</ul>
</div>
<h5 class="mb-25">Property Video</h5>
...
...';https://stackoverflow.com/questions/58888038
复制相似问题