Page 1 of 1

Trouble setting textbox name

Posted: Sun Oct 12, 2008 9:29 am
by midohioit
I was wondering if someone could help me out here...

I have a page that has several rows of data being pulled from MySql.

Currently for testing there are 3 rows. With each row I want the capability of updating just the first row of the three. In each row there are a series of text boxes that are populated from the db. In order for this to work the way I am trying, each text box would have to be a unique name (unless there is a better way of doing it). I am trying to use the ID from the db as it would be unique but having problems getting it to work right. The variable: $form_last_contact is what I am testing on, I will change the other textboxes later. The issue is it updates my first row to whatever is in the textbox in the last row, which would lead me to believe they have to be unique.

Here is the full code:

Code: Select all

 
<?php
 
session_start();
 
$today = date('Y-m-d');
 
include "inc/dbconnect.php";
 
if(!session_is_registered("client_id"))
 
{
 
header("Location: index.php");
 
exit;
 
}
 
 
 
if($remove)
 
{
  $sql2 = "update potiential_clients set decline = 'y' where id = '$chx_remove' ";
         
         $result = mysql_query($sql2);
}
 
if($update)
 
{
  $sql3 = "update potiential_clients set phone = '$form_phone', contact = '$form_contact' , web = '$form_web', 
           last_contact = '$form_last_contact', notes = '$form_notes'
           where id = '$chx_update' ";
           
           echo "update potiential_clients set phone = '$form_phone', contact = '$form_contact' , web = '$form_web', 
           last_contact = '$form_last_contact', notes = '$form_notes'
           where id = '$chx_update' ";
           
          echo "<br>form: $form_last_contact";
         
         $result = mysql_query($sql3);
    
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style2 {font-family: Tahoma}
body {
    background-image: url(gardener_background2.jpg);
}
-->
</style>
</head>
 
<body>
<div align="center">
  <h3>&nbsp;</h3>
  <h3><span class="style2">Potential Client List </span></h3>
  <p>&nbsp;</p>
  <form id="form1" name="form1" method="post" action="potentialclientlist.php">
    <table width="808" border="0" align="left" cellpadding="0" cellspacing="6">
      <tr>
        <td width="120"><div align="left"><span class="style2">Company Name</span></div></td>
        <td width="60"><div align="left"><span class="style2">Phone</span></div></td>
        <td width="108"><div align="left"><span class="style2">Contact Person</span></div></td>
        <td width="132"><div align="left"><span class="style2">Website</span></div></td>
        <td width="60"><div align="left"><span class="style2"> Added </span></div></td>
        <td width="140"><div align="left"><span class="style2">Notes</span></div></td>
        <td width="77" class="style2">Last Called </td>
        <td class="style2">Remove</td>
        <td class="style2">Update</td>
      </tr>
      <?
         $sql = "SELECT * FROM potiential_clients WHERE decline = 'n' ";
         
         $result = mysql_query($sql);
        // get rows for potential clients....
        while ($row = mysql_fetch_array($result))
        {
          $id           = $row["id"];
          $company      = $row["company"];
          $phone        = $row["phone"];
          $contact      = $row["contact"];
          $web          = $row["web"];
          $added2       = $row["added2"];
          $last_contact = $row["last_contact"];
          $notes        = $row["notes"];
          
          $form_last_contact = "lastcontact"."$id";
    ?>
      <tr>
    
        <td height="54" valign="top">
        
        <label>
          <div align="left">
            <input name="<? echo 'form_co_name'.'$id'; ?>" type="text" size="20"  value = "<? echo $company; ?>"/>
          </div>
        </label></td>
        <td valign="top"><div align="left">
          <input name="form_phone" type="text" size="10" maxlength="12" value ="<? echo $phone; ?>"/>
        </div></td>
        <td valign="top"><div align="left">
          <input name="form_contact" type="text" size="18" value = "<? echo $contact; ?>"/>
        </div></td>
        <td valign="top"><div align="left">
          <input name="form_web" type="text" size="22" value = "<? echo $web; ?>" />
        </div></td>
        <td valign="top"><div align="left">
          <input name="form_added" type="text" size="8" value = "<? echo $added2; ?>"/>
        </div></td>
        <td valign="top"><label>
          <div align="left">
            <textarea name="form_notes" cols="14" rows="2" />
            <? echo "$form_last_contact"; ?>
            </textarea>
          </div>
        </label></td>
        <td valign="top"><label></label>
        <input name="<? echo $form_last_contact; ?>" type= 'text' size='10' value = '<? echo $last_contact ?>' /></td>
        <td width="57" valign="top"><div align="center">
          <input type="checkbox" name="chx_remove" value = "<? echo $id; ?>" />
        </div>
    </td>
    <td width="57" valign="top"><div align="center">
          <input type="checkbox" name="chx_update" value = "<? echo $id; ?>" />
        </div>
    </td>
      </tr>     
      <?
        }
        ?>  
    </table>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <table width="346" border="0">
  <tr>
    <td width="18">&nbsp;</td>
    <td width="181">  <p>
      <label>
      <input type="submit" name="update" value="UPDATE" />
      </label>
    </p></td>
    <td width="133"><p>
      <label>
      <input type="submit" name="remove" value="REMOVE" />
      </label>
    </p></td>
  </tr>
</table>
 
  
  </form>
</div>
</body>
</html>