<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>InsertNewCustomer PHP Page</title>
		<style type="text/css">
			h1 {text-align: center; color: blue}
			h2 {font-family: Ariel, sans-serif; text-align: left; color: blue}
			p.footer {text-align: center}
			table.output {font-family: Ariel, sans-serif}
		</style>
	</head>
	<body>
	<?php
		// Get connection
		$DSN = "QACS";
    	$User = "QACS-User";
    	$Password = "QACS-User+password";
    
    	$Conn = odbc_connect($DSN, $User, $Password);	
	
		// Test connection
		if (!$Conn)
			{
				exit ("ODBC Connection Failed: " . $Conn);
			}
		// Create short variable names
		$LastName = $_POST["LastName"];
		$FirstName = $_POST["FirstName"];
		$Phone = $_POST["Phone"];
		$EmailAddress = $_POST["EmailAddress"];
		$Address = $_POST["Address"];
		$City = $_POST["City"];
		$State = $_POST["State"];
		$ZIP = $_POST["ZIP"];
		
		// Create SQL statement to INSERT new data
		$SQLINSERT = "INSERT INTO CUSTOMER ";
		$SQLINSERT .= "VALUES('$LastName', '$FirstName', ";
		$SQLINSERT .= "'$Address', ";
		$SQLINSERT .= "'$City', '$State', '$ZIP', ";
		$SQLINSERT .= "'$Phone', '$EmailAddress')";
	
		// Execute SQL statement
		$Result = odbc_exec($Conn, $SQLINSERT);
	
		// Test existence of result
		echo "<h1>
				The Queen Anne Curiosity Shop CUSTOMER Table
			</h1>
			<hr />";
		if ($Result){	
			echo "<h2>
				New Customer Added:
			</h2>
			<table>
				<tr>";
				echo "<td>LastName:</td>";
				echo "<td>" . $LastName . "</td>";
				echo "</tr>";
				echo "<tr>";
				echo "<td>FirstName:</td>";
				echo "<td>" . $FirstName . "</td>";
				echo "</tr>";
				echo "<td>Phone:</td>";
				echo "<td>" . $Phone . "</td>";
				echo "</tr>";
				echo "<td>EmailAddress:</td>";
				echo "<td>" . $EmailAddress . "</td>";
				echo "</tr>";
				echo "<td>Address:</td>";
				echo "<td>" . $Address . "</td>";
				echo "</tr>";
				echo "<tr>";
				echo "<td>City:</td>";
				echo "<td>" . $City . "</td>";
				echo "</tr>";
				echo "<tr>";
				echo "<td>State:</td>";
				echo "<td>" . $State . "</td>";
				echo "</tr>";
				echo "<td>ZIP:</td>";
				echo "<td>" . $ZIP . "</td>";
				echo "</tr>";
			echo "</table><br /><hr />";
			}
			else {
				exit ("SQL Statement Error: " . $SQL);
			}
			
		// Create SQL statement to read CUSTOMER table data
    	$SQL = "SELECT * FROM CUSTOMER";
 
    	// Execute SQL statement
    	$RecordSet = odbc_exec($Conn,$SQL);
    
    	// Test existence of recordset
    	if (!$RecordSet)
	    	{
	        	exit ("SQL Statement Error: " . $SQL);
	    	}	?>
	    <!--  Page Headers -->
	    <h2>
	        CUSTOMER
            </h2>
	<?php	  
		// Table headers
	    echo "<table class='output' border='1'>
	    		<tr>
	    			<th>LastName</th>
	    			<th>FirstName</th>
	    			<th>Address</th>
	    			<th>City</th>
	    			<th>State</th>
	    			<th>ZIP</th>
	    			<th>Phone</th>
	    			<th>EmailAddress</th>
	    		</tr>";
	    
	    // Table data
	    while($RecordSetRow = odbc_fetch_array($RecordSet))
	    	{
	    	echo "<tr>";
	    	
	    	echo "<td>" . $RecordSetRow['LastName'] . "</td>";
	    	echo "<td>" . $RecordSetRow['FirstName'] . "</td>";
	    	echo "<td>" . $RecordSetRow['Address'] . "</td>";
	    	echo "<td>" . $RecordSetRow['City'] . "</td>";
	    	echo "<td>" . $RecordSetRow['State'] . "</td>";
	    	echo "<td>" . $RecordSetRow['ZIP'] . "</td>";
	    	echo "<td>" . $RecordSetRow['Phone'] . "</td>";
	    	echo "<td>" . $RecordSetRow['EmailAddress'] . "</td>";
	    	echo "</tr>";
	    	}
	    echo "</table>";

	    // Close connection
		odbc_close($Conn);
	?>
		<br />
		<hr />
		<p class="footer">	
			<a href="../QACS/index.html">
				Return to The Queen Anne Curiosity Shop Home Page
			</a>
		</p>
		<hr />
	</body>
</html>
