
<?php
require_once("header.php");
require_once("../includes/quickmysql.php");

echo "<h1>Edit Home</h1>";


/*

// show whats in the post array
// print_r stands for print readable used for displaying arrays
echo "<pre>";
print_r($_POST);
echo "</pre>";

*/

// connect to database
connect();

// check to see if the form has been submitted...
// if it has we need to save the post info into the database
if (isset($_POST['submit'])){
 // save data
 // you need to use mysql_real_escape_strings() on any variable that you
 // use in a mysql query
    $title = mysql_real_escape_string($_POST['title']);
	$content = mysql_real_escape_string($_POST['content']);
	
	// update the row with id=0 
	$query = "UPDATE home SET title = '$title', content = '$content' WHERE id = 0;";
	// run the query
	$result = mysql_query($query);
	 
	
	// if the mysql query worked
	if ($result){
	// use the php.net docs to write date function calls
	  $time = date("g:i:sA");
	  echo "Your information was saved $time. <br /><br />";
	}else{ // if the mysql query didn't work
	  echo "There was an error saving the information. <br /><br />";
	}
}


// get data from a single row of home table
 $data = getSingleRow("home");
  
 // close the mysql connection
disconnect();
?>
<!-- 
basic html form, setting action="" will cause the doc to post to itself
we set the value of the input fields to the values from the data array
-->
<form action="" method="post">
  Title<br />
  <input type="text" name="title" size="50" value="<?php echo $data["title"] ; ?>" /><br /><br />
  Content<br />
  <textarea name="content" cols="50" rows="10"><?php echo $data["content"] ; ?></textarea><br />
  <input type="submit" name="submit" value="Save" />
</form>

<?php
require_once("footer.php");
?>
