Code:
<form action="" method="post">
<table width="500" border="0" align="center">
<tr>
<th scope="row">Title: </th>
<td><div align="center">
<input name='title' type='text' value="<? echo("$title");?>">
</div></td>
</tr>
<tr>
<th scope="row">Subtext:</th>
<td><div align="center">
<input name='subtext' type='text' value="<? echo("$subtext");?>">
</div></td>
</tr>
<tr>
<th scope="row"> </th>
<td><div align="center"></div></td>
</tr>
<tr>
<th scope="row"> </th>
<td><div align="center"></div></td>
</tr>
<tr>
<th scope="row"> </th>
<td><div align="center"></div></td>
</tr>
<tr>
<th scope="row"> </th>
<td><div align="center"></div></td>
</tr>
<tr>
<th scope="row"> </th>
<td><div align="center"></div></td>
</tr>
<tr>
<th scope="row"> </th>
<td><div align="center"></div></td>
</tr>
<tr>
<th scope="row"> </th>
<td><div align="center"></div></td>
</tr>
<tr>
<th scope="row"> </th>
<td><div align="center"></div></td>
</tr>
</table>
<div align="center">
<input value='Save Changes' type='submit'></form>
<?php
//Don't edit this--
$bad = array("<", ">", '"', "'",";");
$good = array(" ", " "," ", " ", " ");
//Don't edit this--end
//add or modify the variables to change using similar format here
$title = $_POST['title'];
$subtext = $_POST['subtext'];
//view this format and modify to suit more or less variables - this stage cleans the user input
$cleantitle = str_replace($bad, $good, $title);
$cleansubtext = str_replace($bad, $good, $subtext);
//heres the new file contents, again look at the format and simply copy & paste to suite more or less variables
$content_to_write =
'<?php
$title = "' . $cleantitle . ' ";
$subtext = "' . $cleansubtext . ' ";
?>';
//filename of the file to hold variables
$filename = '../inc/variables.php';
// Main PHP
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w+')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $content_to_write) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
// echo "Success, variables changed!";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
//Heres the form HTML that you need to add / modify to change the variables edited, note that $_POST['key'] matches up to name='key'
?>
So I have $title = $_POST['title']; and I only want title to be posted/changed when the form button is clicked. Whenever I refresh this page, it $_POST's title.
I have the variable set, and when I open the PHP page the variable posts nothing right away. After I post using the button the variable will show in the box... until the page gets refreshed again.
Anyone?
|