Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help: Trying to get Form to Work
Old 06-10-2005, 10:43 AM Help: Trying to get Form to Work
Novice Talker

Posts: 10
Trades: 0
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>
JBrown1045 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-10-2005, 01:50 PM
Experienced Talker

Posts: 32
Trades: 0
instead of doing all of that in html style do the coding in php and using the print command to print the information out to. That would be your best option if that make senses that is. So dont use the whole <html><body> crap do it all php
rcubes85 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help: Trying to get Form to Work
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10760 seconds with 12 queries