Thanks, that worked fine. Always good to have an outside perspective when it comes to code.
The only problem I seem to be having is that my data base is not being updated. After I find the record with the $name field, I enter a new city (for example) and click submit. This should update the agency_city in the data base with the new city and then display all my fields once again. Well, I checked my data base and the city field is not being updated. Am I missing something where I UPDATE the fields?
Thanks again, Gary
<html>
<title>Tnevni | MySQL Display/Update Clients Table</title>
<link href="style001.css" rel="stylesheet" type="text/css">
<body>
<form method="POST" action="MySQL_client_search.php">
<input type="hidden" name="name" value=<?php print($name);?>>
<input type="hidden" name="redirectlink" value="http://www.tnevni.com/firms/MySQL_db_manipulation.htm">
<link href="style001.css" rel="stylesheet" type="text/css">
<HR width="100%" color=blue><br><br>
<?php
echo "name: " . "$name <br>";
if ($name == "") {
echo "Please Enter Valid AGENT NAME . . . ";
echo "<a href=\"" . $redirectlink . "\">RETURN to MySQL Data Base</a><br>";
echo "<br><br><HR width=\"100%\" color=blue>";
mysql_close();
return;
}
/-- Data Base Commands --/
$user="tnevni";
$password="terraka";
$database="tnevni";
mysql_connect(mysqldb,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
mysql_query($query);
/-- Begin Data Base Search for Agent Name --/
$name = strtolower($name);
$query="SELECT * FROM clients";
$result=mysql_query($query);
$num=mysql_numrows($result);
$status = "no";
$i=0;
while ($i < $num) {
$name_table = mysql_result($result,$i,"agent_name");
$name_table = strtolower($name_table);
if ($name_table == $name) {
$status = "yes";
$id = mysql_result($result,$i,"id");
$agency_name=mysql_result($result,$i,"agency_name");
$agency_telephone=mysql_result($result,$i,"agency_telephone");
$agency_telephone_800=mysql_result($result,$i,"agency_telephone_800");
$agency_fax=mysql_result($result,$i,"agency_fax");
$agency_address_1=mysql_result($result,$i,"agency_address_1");
$agency_address_2=mysql_result($result,$i,"agency_address_2");
$agency_city=mysql_result($result,$i,"agency_city");
$agency_state=mysql_result($result,$i,"agency_state");
$agency_postal_code=mysql_result($result,$i,"agency_postal_code");
$agency_website_url=mysql_result($result,$i,"agency_website_url");
$agent_name=mysql_result($result,$i,"agent_name");
$agent_direct_line=mysql_result($result,$i,"agent_direct_line");
$agent_mobile_line=mysql_result($result,$i,"agent_mobile_line");
$agent_other_line=mysql_result($result,$i,"agent_other_line");
$agent_email_current=mysql_result($result,$i,"agent_email_current");
$agent_email_new=mysql_result($result,$i,"agent_email_new");
$web_host_name=mysql_result($result,$i,"web_host_name");
$web_host_userid=mysql_result($result,$i,"web_host_userid");
$web_host_password=mysql_result($result,$i,"web_host_password");
$i2 = $i;
$i = $num; }
else
++$i;
}
echo "status:" . "$status <br>";
echo "name:" . "$name <br>";
echo "name_table:" . "$name_table <br>";
echo "i2:" . "$i2 <br>";
echo "id:" . "$id <br>";
/-- If Status Not Found - Send Error Message --/
if ($status == "no") {
echo "Agent Name: NOT FOUND . . . ";
echo "<a href=\"" . $redirectlink . "\">RETURN to MySQL Data Base</a><br>";
echo "<br><br><HR width=\"100%\" color=blue>";
mysql_close();
return; }
/-- If Status Found - Query/Update Agent Information --/
/$query = "SELECT FROM clients WHERE agent_name = '$name'";
$result=mysql_query($query);
$id = mysql_result($result,$i2,"id"); */
if ($update_agent_name != "") {
$query="UPDATE clients WHERE id='$id' SET agent_name='$update_agent_name'";
mysql_query($query);
$name = $update_agent_name;
$update_agent_name = ""; }
if ($update_agency_name != "") {
$query="UPDATE clients WHERE id='$id' SET agency_name='$update_agency_name'";
mysql_query($query);
$update_agency_name = ""; }
if ($update_agency_telephone != "") {
$query="UPDATE clients WHERE id='$id' SET agency_telephone='$update_agency_telephone'";
mysql_query($query);
$update_agency_telephone = ""; }
if ($update_agency_telephone_800 != "") {
$query="UPDATE clients WHERE id='$id' SET agency_telephone_800='$update_agency_telephone_800'";
mysql_query($query);
$update_agency_telephone_800 = ""; }
if ($update_agency_fax != "") {
$query="UPDATE clients WHERE id='$id' SET agency_fax='$update_agency_fax'";
mysql_query($query);
$update_agency_fax = ""; }
if ($update_agency_address_1 != "") {
$query="UPDATE clients WHERE id='$id' SET agency_address_1='$update_agency_address_1'";
mysql_query($query);
$update_agency_address_1 = ""; }
if ($update_agency_address_2 != "") {
$query="UPDATE clients WHERE id='$id' SET agency_address_2='$update_agency_address_2'";
mysql_query($query);
$update_agency_address_2 = ""; }
/ ----------------------- Checking City Field Below -----------------/
if ($update_agency_city != "") {
echo "city:" . "$update_agency_city <br>";
$query="UPDATE clients WHERE id='$id' SET agency_city='$update_agency_city'";
mysql_query($query);
$update_agency_city = ""; }
/ ------------------------------- End City Section -------------------- /
if ($update_agency_state != "") {
$query="UPDATE clients WHERE id='$id' SET agency_state='$update_agency_state'";
mysql_query($query);
$update_agency_state = ""; }
if ($update_agency_postal_code != "") {
$query="UPDATE clients WHERE id='$id' SET agency_postal_code='$update_agency_postal_code'";
mysql_query($query);
$update_agency_postal_code = ""; }
if ($update_agency_website_url != "") {
$query="UPDATE clients WHERE id='$id' SET agency_website_url='$update_agency_website_url'";
mysql_query($query);
$update_agency_website_url = ""; }
if ($update_agent_direct_line != "") {
$query="UPDATE clients WHERE id='$id' SET agent_direct_line='$update_agent_direct_line'";
mysql_query($query);
$update_agent_direct_line = ""; }
if ($update_agent_mobile_line != "") {
$query="UPDATE clients WHERE id='$id' SET agent_mobile_line='$update_agent_mobile_line'";
mysql_query($query);
$update_agent_mobile_line = ""; }
if ($update_agent_other_line != "") {
$query="UPDATE clients WHERE id='$id' SET agent_other_line='$update_agent_other_line'";
mysql_query($query);
$update_agent_other_line = ""; }
if ($update_agent_email_current != "") {
$query="UPDATE clients WHERE id='$id' SET agent_email_current='$update_agent_email_current'";
mysql_query($query);
$update_agent_email_current = ""; }
if ($update_agent_email_new != "") {
$query="UPDATE clients WHERE id='$id' SET agent_email_new='$update_agent_email_new'";
mysql_query($query);
$update_agent_email_new = ""; }
if ($update_agent_web_host_name != "") {
$query="UPDATE clients WHERE id='$id' SET agent_web_host_name='$update_agent_web_host_name'";
mysql_query($query);
$update_agent_web_host_name = ""; }
if ($update_agent_web_host_userid != "") {
$query="UPDATE clients WHERE id='$id' SET agent_web_host_userid='$update_agent_web_host_userid'";
mysql_query($query);
$update_agent_web_host_userid = ""; }
if ($update_agent_web_host_password != "") {
$query="UPDATE clients WHERE id='$id' SET agent_web_host_password='$update_agent_web_host_password'";
mysql_query($query);
$update_agent_web_host_password = ""; }
mysql_close();
?>
<table width="760" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="24" colspan="5" align="center" valign="middle"><font size="3" face="Verdana, Arial, Helvetica, sans-serif">DATA BASE CLIENTS
| SEARCH/UPDATE</font></td>
</tr>
<tr>
<td height="23" colspan="5" align="center" valign="middle"> </td>
</tr>
<tr>
<td height="19" align="center" valign="middle" class="borderall"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">DESCRIPTION</font></td>
<td width="11" align="center" valign="middle"> </td>
<td align="center" valign="middle" class="borderall"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">CURRENT</font></td>
<td width="11" align="center" valign="middle" class="bordertop1"></td>
<td align="center" valign="middle" class="borderall"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">UPDATE</font></td>
</tr>
</table>
<br><br>
<HR width="100%" color=blue>
</form>