<?php

include 'db.php';
include 'error.php';
include 'auth.php';

$emailID=$_GET["emailID"];

$emailAddress=$_POST["emailAddress"];
$modifyID=$_POST["modifyID"];


if (empty($emailAddress))
{


		//Event Id exists so need to modify

		if(!($connection=@mysql_connect($hostName, $dbUsername, $dbPassword)))
			die("Could not connect");

		if(!(mysql_select_db ($databaseName, $connection)))
			showerror();


		$viewQuery="SELECT * FROM email WHERE email_id=$emailID";
		//echo($insertQuery);

		if(!($result = @mysql_query($viewQuery,$connection)))
			showerror();

		mysql_close($connection);

		$row=mysql_fetch_array($result);

		include 'header.php';
		?>
				<form name="addBackground" action="email_mod.php" method="post">
				<input type="hidden" name="modifyID" value="<?php echo($row["email_id"]); ?>">
				Email Address for <b><?php echo($row["email_name"]); ?></b>:<br>
				<input type="text" name="emailAddress" size="20" value="<?php echo($row["email_value"]); ?>">
				<p>
				<input type="submit" value="submit"></form>

		<?php
		include 'footer.php';





}else
{

	
	$emailAddress=clean($emailAddress,50);

	if(!($connection=@mysql_connect($hostName, $dbUsername, $dbPassword)))
		die("Could not connect");

	if(!(mysql_select_db ($databaseName, $connection)))
		showerror();

	$insertQuery="UPDATE email SET email_value=\"".$emailAddress."\" WHERE email_id=$modifyID";
	
	
	//echo($insertQuery);

	if((@mysql_query($insertQuery,$connection)) && mysql_affected_rows()==1)
		{
		//print_r($modifyID);
		header("Location:email_mod_success.php?"."emailId=".$modifyID."&status=T");
		}
	else
		header("Location:email_mod_success.php?"."&status=F");




	mysql_close($connection);



}
?>

