|
Hello:
I am trying to do a form where when the person fills out the form and clicks submit, it displays the info on the page right under the form. I have the code, but can't quite figure out what I files I need to create or what info I need to edit. I have tried editing the database info but still have no luck with it working.
<?
// This connects to the database
$conn = mysql_connect("128.........", "dbname", "password") or die(mysql_error());
mysql_select_db('northwind', $conn) or die(mysql_error());
// This gets the user input from the search box and stores it in variable $UserInput
$UserInput = $_GET['search'];
// This statement queries the database using the LIKE query, to include all partial queries as well.
$SqlQuery = "SELECT CustomerID, CompanyName, ContactName, Country FROM customers WHERE CustomerID LIKE '$UserInput%' ";
// This variable stores the query results to be used later
$result = mysql_query ($SqlQuery) or die('Query execution problem: ' . mysql_error());
// Number of rowsreturned by SQL query
$number_rows = mysql_num_rows($result);
// Assign the file to a variable
$File_Name = "query_results.txt";
// Close IP connection
mysql_close($conn);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Output</title>
<meta http-equiv="content-type"content="text/html;charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="text.css" />
</head>
<body>
<h1>Results:</h1>
<p class="small">The query was :<em><?=$SqlQuery?></em></p>
<table>
<tr>
<th>Customer ID</th>
<th>Company Name</th>
<th>Contact Name</th>
<th>Country</th>
</tr>
<?
$SqlQuery = fopen($File_Name , "w") or die ("Unable to open ". $File_Name);
fwrite($SqlQuery, "CustomerID\t CompanyName\t ContactName\t Country\n");
//While there are some rows from the result output the results
while($output_row = mysql_fetch_array($result))
{
?>
<tr>
<td>
<?=htmlentities($output_row[CustomerID]) ?>
</td>
<td>
<?=htmlentities($output_row[CompanyName]) ?>
</td>
<td>
<?=htmlentities($output_row[ContactName]) ?>
</td>
<td>
<?=htmlentities($output_row[Country]) ?>
</td>
</tr>
<? fwrite($SqlQuery, "$output_row[CustomerID]\t") ?>
<? fwrite($SqlQuery, "$output_row[CompanyName]\t") ?>
<? fwrite($SqlQuery, "$output_row[ContactName]\t") ?>
<? fwrite($SqlQuery, "$output_row[Country]\n") ?>
<?
}
fclose($SqlQuery); //Closes the file
?>
</table>
<?
if($number_rows == 0 || $UserInput == NULL)
{
?>
<p><a href="php_input.html">No Rows or you didn't select anything. Please Return to form</a></p>
<?}else{?>
<p><a href="php_input.html">Return to form</a></p>
<p><a href="query_results.txt">Show Results in the test file</a></p>
<?}?>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0!" height="31" width="88" /></a>
</p>
</body>
</html>
|