Forum Moderators: coopster
I have already got it half way working, but I am having a hard time figuring out the rest. Below is what I have so far, which includes the form they fill out. The part where it say's HTML template code, is where I want my page template code to go so it will insert it into the newly created page, but I also can't seem to figure out how to insert all that HTML code without it interpreting the quotes and stuff as PHP.
The below code so far allows the visitor to create the petition, and adds it to the database, but it won't create the page and add the text I want it to add to the new page:
<?php
$db_host = "localhost";
$db_user = "someuser";
$db_pwd = "pass";
$db_name = "mydb";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
<?php
if (!isset($_POST['submit'])) {
?>
<center>
<form action="" method="post">
<table width="100%" border="0" cellpadding="5">
<tr>
<td width="175" align="center" valign="middle"><div align="center"><strong>Full name:</strong></div></td>
<td align="center" valign="middle">
<div align="left">
<input name="fullname" type="text" size="30" maxlength="500" id="fullname">
</div></td>
</tr>
<tr>
<td width="175" align="center" valign="middle"><div align="center"><strong>Address and Zip Code:</strong></div></td>
<td align="center" valign="middle"><p align="left">
<input name="addresszip" type="text" size="30" maxlength="500" id="addresszip"></p> </td>
</tr>
<tr>
<td width="175" align="center" valign="middle"><div align="center"><strong>City:</strong></div></td>
<td align="center" valign="middle">
<div align="left">
<input name="city" type="text" size="30" maxlength="500" id="city" />
</div></td>
</tr>
<tr>
<td width="175" align="center" valign="middle"><div align="center"><strong>Email Address:</strong></div></td>
<td align="center" valign="middle"><p align="left">
<input name="email" type="text" size="30" maxlength="500" id="email"></p> </td>
</tr>
<tr>
<td width="175" align="center" valign="middle"><div align="center"><strong>Phone Number (optional):</strong></div></td>
<td align="center" valign="middle"><p align="left">
<input name="phone" type="text" size="30" maxlength="100" id="phone">
</p> </td>
</tr>
<tr>
<td width="175" align="center" valign="middle"><div align="center"><strong>Petition Title:</strong></div></td>
<td align="center" valign="middle"><p align="left">
<input name="petitiontitle" type="text" size="65" maxlength="1000" id="petitiontitle">
</p> </td>
</tr>
<tr>
<td width="175" align="center" valign="middle"><div align="center"><strong>Petition Statement:</strong></div></td>
<td align="center" valign="middle">
<div align="left">
<textarea name="petitionstate" cols="50" rows="5" id="petitionstate"></textarea>
</div></td>
</tr>
<tr>
<td width="175" align="center" valign="middle"><div align="center"><strong>Comments:</strong></div></td>
<td align="center" valign="middle">
<div align="left">
<textarea name="comments" cols="50" rows="4" id="comments"></textarea>
</div></td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle"><label>
<div align="center">
<input type="submit" name="submit" id="submit" value="Start Petition">
<input type="reset" name="reset" id="reset" value="Reset Form">
</div>
</label></td>
</tr>
</table>
</form>
</center>
<?php
} else {
$fullname=$_POST['fullname'];
$addresszip=$_POST['addresszip'];
$city=$_POST['city'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$petitiontitle=$_POST['petitiontitle'];
$petitionstate=$_POST['petitionstate'];
$comments=$_POST['comments'];
mysql_query("INSERT INTO `petitions` (fullname, addresszip, city, email, phone, petitiontitle, petitionstate, comments) VALUES ('$fullname','$addresszip','$city','$email','$phone','$petitiontitle','$petitionstate','$comments')");
print "<meta http-equiv=\"refresh\" content=\"0;URL=../takeourcityback/petition-form-thankyou.html\">";
fopen ($ourFileName = ("takeourcityback/")uniqid (rand (),true)('.html'));
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite "HTML TEMPLATE CODE
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td width="100%"><? echo $rows['petitionstate'];?></td>
</tr>
</table>";
while($rows=mysql_fetch_array($result)){
}
// close connection
fclose($ourFileHandle);
mysql_close();
}
?>
[edited by: jatar_k at 12:28 pm (utc) on Aug. 9, 2007]
[edit reason] removed user/pass [/edit]
Can you please post the errors you are receiving. From what I've scanned through so far, it looks like your fwrite isn't working correctly. You have this:
fwrite "HTML TEMPLATE CODE
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td width="100%"><? echo $rows['petitionstate'];?></td>
</tr>
</table>";
The format is as follows:
[url=http://www.php.net/fwrite]fwrite[/url] ( resource $handle, string $string [, int $length] )
Read the documentation [php.net] and try to rewrite that line again. If you run into problems let us know :)