I am trying to create a code that will generate a webpage. Here is what I have so far. I am looking to just take data that is queried from our server and display it on a page. Their is a form that is populating the ID on the query and all the information is pulling correctly.
It's just when it comes to creating the file and page contents it's getting lost.
<?php
$id1 = $_POST["id1"];
echo $id1;
echo "<br>";
$id2 = $_POST["id2"];
echo $id2;
echo "<br>";
$id3 = $_POST["id3"];
echo $id3;
echo "<br>";
$name = $_POST["name"];
echo $name;
echo "<br>";
$string = $name."-".date("Y-m-d").".html";
echo $string;
echo "<br>";
$pagename = str_replace(' ', '', $string);//remove spaces
echo $pagename;
echo "<br>";
$newyork = ',NY';
$pagetitle = $_POST["title"];
echo $pagetitle;
echo "<br>";
$con = mysql_connect('****************', '*************', '********');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("squarefeet1", $con);
//Query
if ($id1 != null){
//Query for data
$sql="SELECT * FROM `properties` WHERE `filename` =\"".$id1."\" LIMIT 1";
$result = mysql_query($sql);
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result)){
//save data
$query1address = $row['addr1'];
$query1city = $row['city'];
$query1borough = $row['neighborhood'];
$query1plotsize = $row['plotsize'];
$query1zip = $row['zip'];
}
$address1 = $query1address."\n".$query1city." ".$newyork." ".$query1zip;
echo $address1;
echo "<br>";
}
if ($id2 != null){
//Query for data
$sql="SELECT * FROM `properties` WHERE `filename` =\"".$id2."\" LIMIT 1";
$result = mysql_query($sql);
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result)){
//save data
$query2address = $row['addr1'];
$query2city = $row['city'];
$query2borough = $row['neighborhood'];
$query2plotsize = $row['plotsize'];
$query2zip = $row['zip'];
}
$address2 = $query1address."\n".$query1city." ".$newyork." ".$query1zip;
echo $address1;
echo "<br>";
}
if ($id3 != null){
//Query for data
$sql="SELECT * FROM `properties` WHERE `filename` =\"".$id3."\" LIMIT 1";
$result = mysql_query($sql);
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result)){
//save data
$query3address = $row['addr1'];
$query3city = $row['city'];
$query3borough = $row['neighborhood'];
$query3plotsize = $row['plotsize'];
$query3zip = $row['zip'];
}
$address3 = $query1address."\n".$query1city." ".$newyork." ".$query1zip;
echo $address1;
echo "<br>";
}
mysql_close($con);
$filename = $pagename;
$topcontent = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>($pagetitle)</title>
<style type="text/css" media="screen, print, projection">
body,
html {
margin:0;
padding:0;
font: 12px "Helvetica Neue", Helvetica, Arial, Geneva, sans-serif;
color: #626466; background:#ffffff;
}
a{
color: #626466;
text-decoration: underline;
}
a:hover {
color: #0080ff;
}
#wrap {
width:1166px;
margin:0 auto;
background:#ffffff;
}
#header {
margin-top: 50px;
border-bottom: 1px dashed #CCC;
width: 1100px;
max-width: 1100px;
padding-bottom: 10px;
}
#header a {
text-decoration: none;
color: #CCC;
}
h1 {
margin:0;
font-size: 46px;
letter-spacing: 1px;
text-transform: uppercase;
color: #BBB;
width: 700px;
}
#main {
float:left;
width:966px;
padding:10px 0px 10px 10px;
background:#ffffff;
border-right:1px dashed #CCC;
}
h2 {
margin:0 0 1em;
font-size: 12px;
text-transform: uppercase;
padding-bottom: 5px;
border-bottom: 1px dashed #CCC;
text-align: center;
width: 160px;
margin-top: 10px;
font-weight: normal;
letter-spacing: 1px;
}
h3 {
font-weight: normal;
font-size: 16px;
}
#sidebar {
float:right;
width:160px;
padding:10px;
color: #626466;
background:#ffffff;
}
#sidebar ul {
margin: 10px 0px 0px 0px; padding: 0px;
list-style: none;
text-transform: uppercase;
}
#sidebar li {
padding-top: 5px;
margin: 0px;
}
#sidebar a {
color: #6699ff;
text-decoration: none;
}
#sidebar a:hover {
text-decoration: underline;
}
#footer {
clear:both;
padding:5px 10px;
background:#ffffff;
}
#footer a {
color: #CCC;
text-decoration: none;
}
#footer a:hover {
color: #0080ff;
}
#footer p {
margin:0;
}
* html #footer {
height:1px;
}
</style>
</head>
<body>
<div id="wrap">
<div id="header">
<h1>($pagetitle)</h1>
<script>
$("h1").contents().stretch();
</script> </div>
<!--End of Header-->';
$middlecontent1 = '<table border="0">
<tr>
<td>Picture will be here</td>
<td>($address1)</td>
<td>Google Map will be here</td>
</tr>
';
$middlecontent2 = '<table border="0">
<tr>
<td>Picture will be here</td>
<td>($address2)</td>
<td>Google Map will be here</td>
</tr>
';
$middlecontent3 = '<table border="0">
<tr>
<td>Picture will be here</td>
<td>($address3)</td>
<td>Google Map will be here</td>
</tr>
';
$pagecontent += $topcontent;
if($id1 != null){
$pagecontent += $middlecontent1;
}
if($id2 != null){
$pagecontent += $middlecontent2;
}
if($id3 != null){
$pagecontent += $middlecontent3;
}
echo $pagecontent;
echo "<br>";
// Let's make sure the file exists and is writable first.
if ($pagecontent != null) {
// create new page
file_put_contents($_SERVER['DOCUMENT_ROOT']."/pages/".$filename,$pagecontent);
echo "($pagecontent)";
} else {
echo "The file $filename is not writable";
}
exit;
?>