• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2748
  • Last Modified:

Updating records when listing multiple database entries

I am trying to provide an admin function on a website wherein I have a recordset that lists out all of the news items from a given week and enables the adminstrator to change an entry and update using a button. The code below is not working but I cannot see why. The recordset is ok and lists the correct entries in fields etc., but the update button is not working. I'm sure this is a simple matter of missing something (normally the primary key, but I have that in a hidden field).

<form action="<?php echo $editFormAction; ?>" method="post" name="editEntry" id="editEntry">
                <table>
                <?php // list out the database items from the desired week
                        // Prevent empty fields
                        if ($totalRows_rstNews > 0)
                        {
                              // Start looping the recordset
                              do
                              { ?>
                          <tr>
                                         <td>
                                            <input class="smallFontCenter" name="newsPrimaryKey" type="text" disabled="disabled" value="<?php echo $row_rstNews['news_pk']; ?>" size="2" maxlength="2" readonly="true" /></td>
                                        <td class="col1"><input class="smallFontCenter" name="weekUpdateEntry" type="text" value="<?php echo $row_rstNews['news_week']; ?>" size="2" title="Edit the news entry week number if required" /></td>
                                        <td class="col2"><input class="smallFont" name="titleUpdateEntry" type="text" value="<?php echo $row_rstNews['news_title']; ?>" size="60" title="Edit the news entry title if required"/></td>
                                        <td class="col5"><input class="smallFont" name="urlUpdateEntry" type="text" value="<?php echo $row_rstNews['news_url']; ?>" size="60" title="Edit the news entry URL if required"/></td>
                                        <td class="col6"><input class="smallFont" name="buttonupdate" type="submit" value="Update" title="Click to update this entry in the database"/></td>
                            <input type="hidden" name="primaryKey" value="<?php echo $row_rstNews['news_pk']; ?>" />
                      </tr>
                              <?php } while ($row_rstNews = mysql_fetch_assoc($rstNews));
                        } ?>
                     </table>
                <br />
                <input type="hidden" name="MM_update" value="editEntry" />
                </form>
0
kcalder
Asked:
kcalder
  • 8
  • 6
  • 5
1 Solution
 
nplibCommented:
I don't see much wrong with that code,

the more standard way to loop through arrays with mysql is

while ($row_rstNews = mysql_fetch_array($rstNews)) {
     do stuff
}
instead of
do {
    do stuff
} while ($row_rstNews = mysql_fetch_assoc($rstNews));

how ever, if that doesn't fix the problem, your going to have to most more code. Starting with all the code from this page.
0
 
Mark GilbertSenior Performance EngineerCommented:
From reading your code, I'm assuming that you are creating your form first, then you are looping through a bunch of records which you wish update multiple ones when you click the submit button?  If so, you are going to have to put your ID into an array part of the field name.  For example, simply calling a $_POST['myfieldname'] from a multiple entry list will only call the first one.  What you want to do is loop through all the $_POST['myfieldname'] values and do something while they are looping.  For example:

in your form when you create each row, do this:

<input class="smallFontCenter" name="weekUpdateEntry[<?php echo $row_rstNews['MYNEWSID'];?>]" type="text" value="<?php echo $row_rstNews['news_week']; ?>" size="2" title="Edit the news entry week number if required" />


Notice the weekUpdateEntry[<?php echo $row_rstNews['MYNEWSID'];?>], this is the fieldname[arrayvar] which you will then use to loop through.  As you are using multiple fields for each record, you need to have the same defined for each other field within that row.  Then when you want to process, each field will have an id in the array value which then enables php to process the $_POST['myvar'] successfully for example:

<?
if(is_array($_POST['weekUpdateEntry']))
{
   echo "Update db...<br>";

   foreach ($_POST['weekUpdateEntry'] as $key => $val)
   {
     $query = "update mytable set myfieldname=".$val." where ID=".$key;
     echo $query;
     echo "<br>";
   }

}
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method=POST>"
<?php // list out the database items from the desired week
// Prevent empty fields
if ($totalRows_rstNews > 0)
{
// Start looping the recordset
do
{ ?>
<input class="smallFontCenter" name="weekUpdateEntry[<?php echo $row_rstNews['newsID']; ?>]" type="text" value="<?php echo $row_rstNews['news_week']; ?>" size="2" title="Edit the news entry week number if required" />
<?php } while ($row_rstNews = mysql_fetch_assoc($rstNews));
} ?>
</form>


Hope this helps.
0
 
Mark GilbertSenior Performance EngineerCommented:
One thing I had forgotton to mention regarding your initial code posting is that when you are doing your loop and outputting your hidden ID field, because there are multiples within the form, php will only grab the first one it comes across as it doesn't know there are multiple posts with the same name.  Had you put the form wrappers within the loop for the row then you would have multiple forms which would work independently of each other.  
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
kcalderAuthor Commented:
I am trying to list each record in the set, each of which shows...

- the primary key of the record (disabled text field)
- the news entry title (editable text field)
- the news URL (editable text field)
- an update button

Hence, the update is only relevant to one record at a time. I have a similar arrangement for updating on another page but that uses radio buttons and a single submit button; it works fine. From the sound of it I need to create one form per record rather than loop around within a single form; is that right?
0
 
kcalderAuthor Commented:
...in which case, how does the update record function work in Dreamweaver as it requires specific variables to be tagged to form fields with a named form? If you could provide a short example, that would be ideal. Many thanks.
0
 
nplibCommented:
Can you please post your code?

It makes finding the problem much easier then speculating what the problem actually is.
0
 
kcalderAuthor Commented:
Code for whole page is as below...

<?php require_once('../Connections/EPG_links.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addItem")) {
  $insertSQL = sprintf("INSERT INTO news (news_title, news_url, news_week) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString('http://'.$_POST['shortURL'], "text"),
                       GetSQLValueString($_POST['currentWeekNum'], "int"));

  mysql_select_db($database_EPG_links, $EPG_links);
  $Result1 = mysql_query($insertSQL, $EPG_links) or die(mysql_error());
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "weekNum")) {
  $updateSQL = sprintf("UPDATE newsWeek SET weekNumber=%s WHERE week_pk=%s",
                       GetSQLValueString($_POST['weekToDisplay'], "int"),
                       GetSQLValueString($_POST['weekPK'], "int"));

  mysql_select_db($database_EPG_links, $EPG_links);
  $Result1 = mysql_query($updateSQL, $EPG_links) or die(mysql_error());
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "listingWeek")) {
  $updateSQL = sprintf("UPDATE newsWeek SET weekNumber=%s WHERE week_pk=%s",
                       GetSQLValueString($_POST['showItemsFromWeek'], "int"),
                       GetSQLValueString($_POST['weekPrimaryKey'], "int"));

  mysql_select_db($database_EPG_links, $EPG_links);
  $Result1 = mysql_query($updateSQL, $EPG_links) or die(mysql_error());
}

if ((isset($_POST['news_pk'])) && ($_POST['news_pk'] != "")) {
  $deleteSQL = sprintf("DELETE FROM news WHERE news_pk=%s",
                       GetSQLValueString($_POST['news_pk'], "int"));

  mysql_select_db($database_EPG_links, $EPG_links);
  $Result1 = mysql_query($deleteSQL, $EPG_links) or die(mysql_error());
}

mysql_select_db($database_EPG_links, $EPG_links);
$query_rstNews = "SELECT * FROM news  LEFT JOIN newsWeek ON newsWeek.week_pk = '2' WHERE news_week = weekNumber ORDER BY news_pk";
$rstNews = mysql_query($query_rstNews, $EPG_links) or die(mysql_error());
$row_rstNews = mysql_fetch_assoc($rstNews);
$totalRows_rstNews = mysql_num_rows($rstNews);

mysql_select_db($database_EPG_links, $EPG_links);
$query_rstDisplayNewsWeek = "SELECT * FROM newsWeek WHERE week_pk = 1";
$rstDisplayNewsWeek = mysql_query($query_rstDisplayNewsWeek, $EPG_links) or die(mysql_error());
$row_rstDisplayNewsWeek = mysql_fetch_assoc($rstDisplayNewsWeek);
$totalRows_rstDisplayNewsWeek = mysql_num_rows($rstDisplayNewsWeek);

mysql_select_db($database_EPG_links, $EPG_links);
$query_rstEditNewsWeek = "SELECT * FROM newsWeek WHERE week_pk = 2";
$rstEditNewsWeek = mysql_query($query_rstEditNewsWeek, $EPG_links) or die(mysql_error());
$row_rstEditNewsWeek = mysql_fetch_assoc($rstEditNewsWeek);
$totalRows_rstEditNewsWeek = mysql_num_rows($rstEditNewsWeek);
?>
<!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>Edit news and events</title>
<link href="../css/style1.css" rel="stylesheet" type="text/css" />
<link href="../css/style1_sunrise.css" rel="stylesheet" type="text/css" />
<?php require('../includes/header.inc.php'); ?>
</head>
<body>
<h2>News administration</h2>
<?php
// Establish the current week number in the year
$now = time();
$weekNum = date('W', $now);
?>
<table>
      <tr>
        <td>
            <form action="<?php echo $editFormAction; ?>" method="POST" name="addItem" id="addItem">
                        <table>
                      <tr>
                          <td><h3>Add an entry to the database</h3></td>
                        </tr>
                        <tr>
                            <td><p>Title (maximum 128 characters)</p></td>
                            <td class="col3"><input name="title" type="text" size="85" maxlength="128" title="Insert the Title text here"/></td>
                        </tr>
                        <tr>
                            <td><p>URL (maximum 128 characters, exclude http://)</p></td>
                            <td class="col3"><input name="shortURL" type="text" size="85" maxlength="128" title="Insert the site URL here"/>
                            </td>
                        </tr>
                        <tr>
                            <td class="col3"><input class="smallFont" name="Submit" type="submit" value="Add item to database" title="Click to add item to the database"/></td>
                                <input name="currentWeekNum" type="hidden" value="<?php echo $weekNum; ?>" />
                      </tr>
                </table>
              <input type="hidden" name="MM_insert" value="addItem" />
            </form>      
          <br />
        </td>      
      </tr>
      <tr>
            <td>
           
           
            <form action="<?php echo $editFormAction; ?>" method="post" name="weekNum" id="weekNum">
                  <table>
                    <tr>
                        <td><h3>Set live display by week number</h3></td>
                    </tr>
                    <tr>
                        <td><p>The week number at today's date is</p></td>
                        <td class="col3"><input class="displayWeekNumber" name="weekCurrent" type="text" disabled="disabled" value="<?php echo $weekNum; ?>" size="2" maxlength="2" readonly="true" /></td>
                    </tr>
                    <tr>
                        <td><p>News entries are currently displayed for week</p></td>
                        <td class="col3"><input class="center" name="weekDisplayed" type="text" disabled="disabled" value="<?php echo $row_rstDisplayNewsWeek['weekNumber']; ?>" size="2" maxlength="2" readonly="true" /></td>
                    </tr>
                    <tr>
                        <td><p>Display entries in week (leave blank if as current)</p></td>
                        <td class="col3"><input class="center" name="weekToDisplay" type="text" size="2" maxlength="2" title="Insert the week of the year for which items will be displayed on the web site"/></td>
                        <td class="col4"><input class="smallFont" name="Submit" type="submit" value="Set" title="Click to change the currently displayed week"/></td>
                      <input name="weekPK" type="hidden" value="1" />
                    </tr>
                </table>
            <input type="hidden" name="MM_update" value="weekNum" />
            </form>
            <br />
          </td>
      </tr>
      <tr>
          <td>
                  
           
      <form action="<?php echo $editFormAction; ?>" method="post" name="listingWeek" id="listingWeek">
                  <table>
                    <tr>
                        <td><h3>Edit an existing database entry</h3></td>
                    </tr>
                    <tr>
                        <td><p>Week containing item(s) to edit</p></td>
                        <td class="col3"><input class="center" name="showItemsFromWeek" type="text" value="<?php echo $row_rstEditNewsWeek['weekNumber']; ?>" size="2" maxlength="2" title="Insert the week of the year for which you wish items to be displayed below"/></td>
                        <td class="col4"><input class="smallFont" name="updateListingWeek" type="submit" value="Set" title="Click to change the currently listed week"/></td>
                        <?php // hidden field with primary key of weekNumber in for record updating ?>
                        <input name="weekPrimaryKey" type="hidden" value="2" />
                    </tr>
                </table>  
            <input type="hidden" name="MM_update" value="listingWeek" />
              <br />
            </form>
             
            <form action="<?php echo $editFormAction; ?>" method="post" name="editEntry" id="editEntry">
                <table>
                <?php // list out the database items from the desired week
                        // Prevent empty fields
                        if ($totalRows_rstNews > 0)
                        {
                              // Start looping the recordset
                              do
                              { ?>
                          
                          <tr>
                                         <td>
                                            <input class="smallFontCenter" name="newsPrimaryKey<?php echo $row_rstNews['news_pk']; ?>; ?>" type="text" disabled="disabled" value="<?php echo $row_rstNews['news_pk']; ?>" size="2" maxlength="2" readonly="true" /></td>
                                        <td class="col1"><input class="smallFontCenter" name="weekUpdateEntry<?php echo $row_rstNews['news_pk']; ?>" type="text" value="<?php echo $row_rstNews['news_week']; ?>" size="2" title="Edit the news entry week number if required" /></td>
                                        <td class="col2"><input class="smallFont" name="titleUpdateEntry<?php echo $row_rstNews['news_pk']; ?>" type="text" value="<?php echo $row_rstNews['news_title']; ?>" size="60" title="Edit the news entry title if required"/></td>
                                        <td class="col5"><input class="smallFont" name="urlUpdateEntry<?php echo $row_rstNews['news_pk']; ?>" type="text" value="<?php echo $row_rstNews['news_url']; ?>" size="60" title="Edit the news entry URL if required"/></td>
                            <input type="hidden" name="primaryKey<?php echo $row_rstNews['news_pk']; ?>" value="<?php echo $row_rstNews['news_pk']; ?>" />
                                  </tr>
                               <?php } while ($row_rstNews = mysql_fetch_assoc($rstNews));
                        } ?>
                     </table>
                <br />
                  <input type="hidden" name="MM_update" value="editEntry" />
                           <td class="col1"><input class="smallFont" name="buttonupdate" type="submit" value="Update" title="Click to update this entry in the database"/></td>
            </form>    
           
         
                       <form action="<?php echo $editFormAction; ?>" method="post" name="deleteEntry" id="deleteEntry">
            <table>
                  <tr>
                      <td><h3>Delete an existing database entry</h3></td>
                    </tr>
                    <tr>
                      <td><input class="center" name="ItemToDelete" type="text" size="2" maxlength="2" title="Insert the index number of the entry you wish to delete"/></td>
                      <td class="col1"><input class="smallFont" name="Submit" type="submit" value="Delete entry" title="Click to delete the entry"/></td>
                    </tr>
            </table>
            <br />
            <input type="hidden" name="primKey" value="<?php $row_rstNews['week_pk']; ?>" />
            </form>
          </td>
       </tr>
</table>
</body>
</html>
<?php
mysql_free_result($rstNews);
mysql_free_result($rstDisplayNewsWeek);
mysql_free_result($rstEditNewsWeek);
?>
0
 
kcalderAuthor Commented:
By the way, I think I get the point of what Ingwa's stating, but am unsure as to how to create the array within the database. I have tried previously to uniquely identify each record field type by using a manual counter ($count++) but of course Dreamweaver didn't like it. I was going to try and go around Dreamweaver's database interface functions and write the MySQL commands directly but I'll wait to see what else comes back now that I have posted the code.
0
 
nplibCommented:
the trouble with your script is these lines

$row_rstNews = mysql_fetch_assoc($rstNews);
$row_rstDisplayNewsWeek = mysql_fetch_assoc($rstDisplayNewsWeek);
$row_rstEditNewsWeek = mysql_fetch_assoc($rstEditNewsWeek);

I'm not entirely sure why you can't do that, but ever since I started PHP programing, if I try to do something like that it returns 0 results, and it empties the recordset.

you need to remove those lines and when your ready to loop through the record set do something like I said initally.
while ($row_rstNews= mysql_fetch_assoc($rstNews)) {
  do stuff;
}
So with your above code it would be like

<form action="<?php echo $editFormAction; ?>" method="post" name="editEntry" id="editEntry">
                <table>
                <?php // list out the database items from the desired week
                        // Prevent empty fields
                        if ($totalRows_rstNews > 0)
                        {
                              // Start looping the recordset
                              while ($row_rstNews = mysql_fetch_assoc($rstNews));
                              { ?>
                          <tr>
                                         <td>
                                            <input class="smallFontCenter" name="newsPrimaryKey" type="text" disabled="disabled" value="<?php echo $row_rstNews['news_pk']; ?>" size="2" maxlength="2" readonly="true" /></td>
                                        <td class="col1"><input class="smallFontCenter" name="weekUpdateEntry" type="text" value="<?php echo $row_rstNews['news_week']; ?>" size="2" title="Edit the news entry week number if required" /></td>
                                        <td class="col2"><input class="smallFont" name="titleUpdateEntry" type="text" value="<?php echo $row_rstNews['news_title']; ?>" size="60" title="Edit the news entry title if required"/></td>
                                        <td class="col5"><input class="smallFont" name="urlUpdateEntry" type="text" value="<?php echo $row_rstNews['news_url']; ?>" size="60" title="Edit the news entry URL if required"/></td>
                                        <td class="col6"><input class="smallFont" name="buttonupdate" type="submit" value="Update" title="Click to update this entry in the database"/></td>
                            <input type="hidden" name="primaryKey" value="<?php echo $row_rstNews['news_pk']; ?>" />
                      </tr>
                              <?php }
                        } ?>
                     </table>
                <br />
                <input type="hidden" name="MM_update" value="editEntry" />
                </form>
0
 
kcalderAuthor Commented:
Wow, that IS strange because that code was generated by Dreamweaver, which is the platform I am developing on, and I have never had cause to question it before. If I were developing in pure PHP rather than relying on Dreamweaver to generate common function code, my code would look at lot different. Also, I don't see how switching from a do...while loop to a while... loop would make any difference. They are just two different forms of looping; coming from a C/C++ background, my understanding has always been that one's choice is dependent mainly on whether the '+1' error would occur in your code if you used one or the other.

I think that ingwa must have a point about generating unique field identifiers however. It makes sense that everything in the $POST array has to be uniquely identifiable.

Nevertheless, you have been kind enough to respond to my query so I'll give it a whirl tomorrow and post the results.
0
 
Mark GilbertSenior Performance EngineerCommented:
hi kcalder, there's nothing wrong with the code that is calling your mysql or the code you are looping to generate your recordset.  As they are correctly returning to the page, that eliminates any problems with that part of the code.  What you need to do though is to create arrays from the recordset when everything gets rendered to the page so that when you return it to php, php will know what to do.  

Therefore, to be as simplistic as possible, think of it this way.  When you echo a recordset to the page on a single record edit page (one of dreamweavers many behaviours), it creates a hidden field with the record id which then lets php know which record it's editing when sending an update to mysql.  This works well with a single recordset or a single form per record per submit button, so that each form is accompanied by a unique ID.

So, for your page to render multiple rows, with multiple form fields, a set of fields for each row, and a single form so that you do a bunch of changes to a bunch of records before submitting, you need to create arrays from the fields, containing the ID so that php can then loop through.  for example, if we had:

<form><input type=text value=record1 name=title>
<input type=text value=record2 name=title>
<input type=text value=record3 name=title>
</form>

With the above form, everything appears to be correct.  The rows are being returned within the form, and the values from each record have been echoed to the form field called title.  When we submit this to php however, there will only be one title field that php sees.  By doing the following we get intelligent recordsets, with unique identifiers:

<form><input type=text value=record1 name=title[1]>
<input type=text value=record2 name=title[2]>
<input type=text value=record3 name=title[3]>
</form>

now, when we submit the form, php will know that there is more than one title field, and that the field contains a key value which then used in combination with the code i provided in my first post, allows php to loop through that array of posts, to then apply and update to the database.
0
 
kcalderAuthor Commented:
Of course, what you are saying about creating arrays makes sense. The only problem is that Dreamweaver won't wear it. To me, the obvious tag for the name parameter array would be the primary key of the record, such that (e.g.) name="weekUpdateEntry[<?php echo $row_rstNews['news_pk']; ?>]", copying your previous post. However, if I opt to produce a record update using the Dreamweaver wizard, it complains with an error box stating

Column 'news_title' is mapped to a form element that does not exist. Please map the column to an existing form element or set its value to 'None'.

I have already done the former (so I thought) and clearly cannot do the latter. Alternatively, I will have to jetison all DW wizard methods on the page and code the MySQL queries manually. Have you any views on this?
0
 
Mark GilbertSenior Performance EngineerCommented:
Ahh I see where your problem is now.  Due to the ways of DW, you won't be able to automatically do this using the built in server behaviors.  What you would do however is first setup the page using DW behaviors, I.E:

1) Create a record set page, and return all the results of your query to the page.  
2) create an edit record page, with all the fields that you wish to update in a single row.
3) copy the code from the recordset page to the edit page, ensuring that the query code is in the headers, the loop for the rows is in the table etc, and copy the table into the form tags.  Copy across the form fields into the row, and have the submit button at the very end of the page.  Manually edit the recordset results so that the ID value is in each form field within the loop.
4) I've created the following code which is a modification of the initial post I made, with extra items so that you can see how the page is constructed.  Remember, because you are going outside of the DW behaviours, you will need to understand the modifications made so that your application can be customised for your specific needs.  For example, I've included a copy of one of your update scripts from DW, but I haven't included the delete.  Basically you need to check for various fields as an array value (check the form, and the top php code for how I call these arrays) and then make logical changes.  If you make them right, your application will be so much more powerful than DW behavior extensions.

<?php require_once('../Connections/EPG_links.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
// First check to see that a value has been posted.  For this purpose, I've created a hidden field for each recordset row and simply created an array out of it's value:
// <input name="myRecord[<?php echo $counter; ?>]" type="hidden" value="<?php echo $counter;?>" />
//
if(isset($_POST['myRecord'])){
// Next, we check to see that it's an array.  If it's not an array, we will be told that php detected a post, but did not detect an array, which means that the square brackets are missing (these create the array) []

      if(is_array($_POST['myRecord']))
      {
            // Lets say that we are updating the database.  
            echo "Update db...<br>";
      
            foreach ($_POST['myRecord'] as $key => $val)
            {
             
             // An example DW Update behaviour copied from your code follows, BUT modify accordingly and commented out so that you can mod:
                  if(isset($_POST['myRecordDelete'][$key])){
                        // The delete record checkbox has been detected for this recordset, so put your delete behaviour script into here, and modify.
                        echo "Deleting record " . $key;
                  }
                  else{
                        // The delete checkbox was not detected, so lets update the record.  Note, you can do multiple values in here, simply call each fieldname as per my commented out line in the middle of the GetSQLValueString() set with the array key value and remember to change the type, below you have int, it could be text, or date.
                         echo "Updating record " . $_POST['weekUpdateEntry'][$key];
                        
/*                        $updateSQL = sprintf("UPDATE newsWeek SET weekNumber=%s WHERE week_pk=%s",
                                                   GetSQLValueString($_POST['weekToDisplay'], "int"),
                                                   //GetSQLValueString($_POST['anotherField'][$key], "int"),
                                                   GetSQLValueString($key, "int"));
                        
                        mysql_select_db($database_EPG_links, $EPG_links);
                        $Result1 = mysql_query($updateSQL, $EPG_links) or die(mysql_error());
                        
                        
                        
*/                        $query = "update mytable set myfieldname=".$val." where ID=".$key;
                        echo $query;
                        echo "<br>";
                  }
            }
      
      }
}
?><!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=UTF-8" />
<title>Untitled Document</title>
</head>

<body><form action="<?php echo $_SERVER['PHP_SELF'];?>" method=POST>
<?php for ($counter = 1; $counter <= 5; $counter++)
{
//stuff
?>
<input name="myRecord[<?php echo $counter; ?>]" type="hidden" value="<?php echo $counter;?>" />
<input class="smallFontCenter" name="weekUpdateEntry[<?php echo $counter; ?>]" type="text" value="var-<?php echo $counter; ?>" size="2" title="Edit the news entry week number if required" />
<input name="myRecordDelete[<?php echo $counter; ?>]" type="checkbox" value="Y" /><br />
<?php } ?>

<label>
<input type="submit" name="button" id="button" value="Submit" />
</label>
</form>
</body>
</html>


As your application is quite complicated I haven't modified your own code as I believe you could do some considerable changes to it to optimise it further.  For example, instead of updating 1 value for a recordset per behaviour, you can modify multiple values as in the example I provided.  Hope this helps, and good luck.
0
 
Mark GilbertSenior Performance EngineerCommented:
Oh heck, I've just seen your post regarding individual forms per record.  In this case, I would create an update record page, and trick dreamweaver in looking for the record with ID = 1.  Then modify the select code, and change the select * from tablename.  That will then return all the records.  Then where the form is created on the page, create a repeat recordset and ensure that the <?php do{ ?> and <?php } while (...?> are wrapping the form start and end.  Forget any of the array stuff.  This way, each record has it's own form, with it's own submit per row.  If you submit one, dreamweaver will listen to that one.  

Hope this clarifies...I could post code if you need it.
0
 
nplibCommented:
This isn't a solution statement, just a comment. I've been programming for a number of years using notepad. Don't rely on tools, because they are not as flexible as your imagination.

I'll post an example code of something I have done that you are trying to do, so you can get an idea of what I was trying to say in my earlier post.
0
 
nplibCommented:
This is my admin.php page.....
<?php
session_start();
if (!$_SESSION['username']) {
      header("location: https://secure.newmarketpl.ca");
}
$loginSuccess = $_SESSION['loginFailure'];
#$userName = $_POST['logUser'];
#$lastLog = $_POST['logLast'];
#$passExpire = $_POST['logExp'];
#if ($passExpire == "") {
#      $passExpire = date("j/m/Y");
#}
#$timestamp = strtotime($passExpire);
$sessionUser = $_SESSION['username'];
#$passWord = $_SESSION['PWord'];
#$sessionExpire = $_SESSION['eXp'];
#$sessionLast = $_SESSION['lastLog'];
$dBase = $_SESSION['Sel'];
$dB = $_GET['db'];
#echo date("j/m/Y", $timestamp)." < ".date("j/m/Y");
//if (((date("j/m/Y", $timestamp)) > (date("j/m/Y"))) && ($loginSuccess == "false")) {
//      session_unset();
//      header("location:password.php?user=".$userName."&passexp=Expired");
//}
?>
<!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>Admin Login</title>
<script language="javascript" type="text/javascript">
if (document.layers)
  document.captureEvents(Event.KEYDOWN);
  document.onkeydown =
    function (evt) {
      var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
      if (keyCode == 13)   //13 = the code for pressing ENTER
      {
         document.admin.submit();
      }
    }
</script>
</head>

<body>
<form name="admin" action="checklogin.php" method="post">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
      <tr>
            <td align="center">
                  <table id="Table_01" width="600" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                          <td colspan="3">
                                    <?php
                                          if (($loginSuccess == "true") || ($loginSuccess == "")) {
                                                echo("<img src='images/nwmtconnectionadmin_01.gif' alt='' width='600' height='55' />");
                                          } else {
                                    ?>
                                    <table id="Table_01" width="600" border="0" cellpadding="0" cellspacing="0">
                                          <tr>
                                                <td rowspan="3">
                                                      <img src="images/nwmtconnectionhead_01.gif" width="50" height="55" alt=""></td>
                                                <td colspan="6">
                                                      <img src="images/nwmtconnectionhead_02.gif" width="394" height="5" alt=""></td>
                                                <td rowspan="2">
                                                      <a href="../admin.php"><img src="images/nwmtconnectionhead_03.gif" width="156" height="45" alt="" border="0"></a></td>
                                          </tr>
                                          <tr>
                                                <td>
                                                      <a href="admin.php?db=add"><img src="images/nwmtconnectionhead_04.gif" width="40" height="40" alt="" border="0"></a></td>
                                                <td>
                                                      <img src="images/nwmtconnectionhead_05.gif" width="10" height="40" alt=""></td>
                                                <td>
                                                      <a href="admin.php?db=del"><img src="images/nwmtconnectionhead_06.gif" width="40" height="40" alt="" border="0"></a></td>
                                                <td>
                                                      <img src="images/nwmtconnectionhead_07.gif" width="10" height="40" alt=""></td>
                                                <td>
                                                      <a href="admin.php?db=update"><img src="images/nwmtconnectionhead_08.gif" width="40" height="40" alt="" border="0"></a></td>
                                                <td>
                                                      <img src="images/nwmtconnectionhead_09.gif" width="254" height="40" alt=""></td>
                                          </tr>
                                          <tr>
                                                <td colspan="7">
                                                      <img src="images/nwmtconnectionhead_10.gif" width="550" height="10" alt=""></td>
                                          </tr>
                                    </table>
                                    <?php
                                          }
                                    ?>
                              </td>
                        </tr>
                        <tr>
                              <td colspan="3">
                                    <img src="images/nwmtconnectionadmin_02.gif" width="600" height="44" alt=""></td>
                        </tr>
                        <tr>
                              <td colspan="3" bgcolor="#333333" align="center"><br />
                              <?php
                                    if (($loginSuccess == "true") || ($loginSuccess == "")) {
                              ?>
                                    <font face="Verdana, Arial, Helvetica, sans-serif" color="#FFCC99">UserName:</font>
                                    <input type="text" size="20" name="uName" />
                                    <font face="Verdana, Arial, Helvetica, sans-serif" color="#ffcc99">Password:</font>
                                    <input type="password" size="20" name="pWord" /><br /><br />
                              <?php
                              } else {
                              ?>
                                    <font face="Verdana, Arial, Helvetica, sans-serif" color="#FFCC99">Current User is: <?=$sessionUser?>
                                    <input type="hidden" name="uName" value="<?=$sessionUser?>" />
                                    <!--<input type="hidden" name="pWord" value="<?=$passWord?>" />--><br />
                                    <!--You were last logged on <?=$sessionLast?> and your password expires on <?=$sessionExpire?></font>-->
                              <?php
                              }
                              ?>
                              </td>
                        </tr>
                        <tr>
                              <td align="center" bgcolor="#333333" width="444">
                              <font face="Verdana, Arial, Helvetica, sans-serif" color="#ffcc99">Choose Database:</font>
                              <?php
                                    if (($loginSuccess == "true") || ($loginSuccess == "")) {
                              ?>
                                    <select name="SelectDatabase">
                              <?php
                                    } else {
                              ?>
                                    <select name="SelectDatabase" onchange="javascript:document.admin.submit();">
                              <?php
                                    }
                                    if ($dBase == "Pathfinder") {
                              ?>
                                    <option value="Pathfinder" selected="selected">Resource Centre Pathfinder</option>
                              <?php
                                    } else {
                              ?>
                                    <option value="Pathfinder">Resource Centre Pathfinder</option>
                              <?php
                                    }
                                    if ($dBase == "Volunteer") {
                              ?>
                                    <option value="Volunteer" selected="selected">Volunteer Opportunities</option>
                              <?php
                                    } else {
                              ?>
                                    <option value="Volunteer">Volunteer Opportunities</option>
                              <?php
                                    }
                                    if ($dBase == "Links") {
                              ?>
                                    <option value="Links" selected="selected">Links</option>
                              <?php
                                    } else {
                              ?>
                                    <option value="Links">Links</option>
                              <?php
                                    }
                              ?>
                              </select>
                              </td>      
                              <td><?php
                                          if (($loginSuccess == "true") || ($loginSuccess == "")) {
                                                echo("<a href='#' onclick='javascript:document.admin.submit();'><img src='images/nwmtconnectionadmin_05.gif' width='146' height='47' alt='' border='0'></a></td>");
                                          } else {
                                                echo("<a href='signout.php'><img src='images/nwmtconnectionadminout_03.gif' width='146' height='47' alt='' border='0'></a></td>");
                                          }
                                    ?>
                              <td>
                                    <img src="images/nwmtconnectionadmin_06.gif" width="10" height="47" alt=""></td>
                        </tr>
                        <tr>
                              <td colspan="3">
                                    <img src="images/nwmtconnectionadmin_07.gif" width="600" height="65" alt=""></td>
                        </tr>
                  </table>
            </td>
      </tr>
</table>
</form>
<?php
if ($dBase == "Pathfinder") {
      require_once("rcp.php");
}
if ($dBase == "Volunteer") {
      require_once("vol.php");
}
if ($dBase == "Links") {
      require_once("links.php");
}
?>
<p align="left">Ver 0.9b</p>
</body>
</html>
at the bottom here you will see three require statements, one is rec.php, here is that php file.
<?php
      if ($_GET['success'] == 1) {
?>
<script language="javascript">
      alert("Reccord added successfully");
</script>
<?
      }
      require("update_mysqlconn.php");
      mysqlUpdate("connection");
      if (($loginSuccess == "false") && ($dB == "add")) {
            echo("<form name='addDB' action='add.php' method='post'>");
            echo("<table cellspacing='0' cellpadding='0' border='0' align='center'>");
            echo("<tr><td width='50'></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='50'></td></tr>");
            echo("<tr><td width='50'><img src='images/tableheader_01.gif' width='50' height='55' alt='' /></td>");
            echo("<td background='images/tableheader_02.gif' colspan='9'></td>");
            echo("<td width='50'><img src='images/tableheader_03.gif' height='55' width='50' alt=''></td></tr>");
            echo("<tr bgcolor='#333333'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#ffcc99'>Subject</font></td><td colspan='8' align='center'><textarea name='addSubject' rows='2' cols='70'></textarea></td><td></td></tr>");
            echo("<tr bgcolor='#ffcc99'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#333333'>Author</font></td><td colspan='8' align='center'><textarea name='addAuth' rows='2' cols='70'></textarea></td><td></td></tr>");
            echo("<tr bgcolor='#333333'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#ffcc99'>Title</font></td><td colspan='8' align='center'><textarea name='addTitle' rows='2' cols='70'></textarea></td><td></td></tr>");
            echo("<tr bgcolor='#ffcc99'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#333333'>Extra Title</font></td><td colspan='8' align='center'><textarea name='addExtra' rows='2' cols='70'></textarea></td><td></td></tr>");
            echo("<tr bgcolor='#333333'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#ffcc99'>Location</font></td><td colspan='8' align='center'><textarea name='addLocation' rows='2' cols='70'></textarea></td><td></td></tr>");
            echo("<tr bgcolor='#ffcc99'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#333333'>Publisher</font></td><td colspan='8' align='center'><textarea name='addPub' rows='2' cols='70'></textarea></td><td></td></tr>");
            echo("<tr bgcolor='#333333'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#ffcc99'>Pub_date</font></td><td colspan='8' align='center'><textarea name='addPubDate' rows='2' cols='70'></textarea></td><td></td></tr>");
            echo("<tr bgcolor='#ffcc99'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#333333'>Call No.</font></td><td colspan='8' align='center'><textarea name='addCall' rows='2' cols='70'></textarea></td><td></td></tr>");
            echo("<tr bgcolor='#333333'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#ffcc99'>Des.</font></td><td colspan='8' align='center'><textarea name='addDes' rows='2' cols='70'></textarea></td><td></td></tr>");
            echo("<tr bgcolor='#ffcc99'><td colspan='11' height='5'><img src='images/spacer.gif width='1' height='5' alt='' /></td></tr>");
            echo("<tr bgcolor='#333333'><td colspan></td><td colspan='9' align='center'><a href='#' onclick='javascript:document.addDB.submit();'><img src='images/add.gif' alt='' border='0'></a></td><td></td></tr>");
            echo("</table></form>");
      }
      if (($loginSuccess == "false") && ($dB == "del")) {
            $sql = "select * from Pathfinder order by Subject;";
            $results = mysql_query($sql);
            
            echo("<form name='delDB' action='del.php' method='post'>");
            echo("<table cellspacing='0' cellpadding='0' border='0' align='center'>");
            echo("<tr><td width='50'></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td></td></tr>");
            echo("<tr><td width='50'><img src='images/tableheader_01.gif' width='50' height='55' alt='' /></td>");
            echo("<td background='images/tableheader_02.gif' colspan='9'></td>");
            echo("<td background='images/tableheader_02.gif' align='right'><img src='images/tableheader_03.gif' height='55' width='50' alt='' align='right'></td></tr>");
            while ($rs = mysql_fetch_array($results)) {
                  echo("<tr bgcolor='#333333'><td><input type='checkbox' name='delid[]' value='".$rs['ID']."' /></td><td><font face='Verdana' color='#ffcc99'>".$rs['Subject']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Author']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Title']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Extra_Title']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Location']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Publisher']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Pub_Date']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Call_Num']."</font></td><td colspan='2'><font face='Verdana' color='#ffcc99'>".$rs['Des']."</font></td></tr>");
                  echo("<tr bgcolor='#ffcc99'><td colspan='11' height='5'><img src='images/spacer.gif width='1' height='5' alt='' /></td></tr>");
            }
            echo("<tr bgcolor='#333333'><td></td><td colspan='9' align='center'><a href='#' onclick='javascript:document.delDB.submit();'><img src='images/del.gif' alt='' border='0'></a></td><td></td></tr>");
            echo("</table></form>");
      }
      
      if (($loginSuccess == "false") && ($dB == "update")) {
            $sql = "select * from Pathfinder order by Subject;";
            $results = mysql_query($sql);
      
            $updateRecord = $_POST['updateid'];
            if ($updateRecord == "") {
                  echo("<form name='updateDB' action='admin.php?db=update' method='post'>");
                  echo("<table cellspacing='0' cellpadding='0' border='0' align='center'>");
                  echo("<tr><td width='50'></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td></td></tr>");
                  echo("<tr><td width='50'><img src='images/tableheader_01.gif' width='50' height='55' alt='' /></td>");
                  echo("<td background='images/tableheader_02.gif' colspan='9'></td>");
                  echo("<td background='images/tableheader_02.gif' align='right'><img src='images/tableheader_03.gif' height='55' width='50' alt='' align='right'></td></tr>");
                  while ($rs = mysql_fetch_array($results)) {
                        echo("<tr bgcolor='#333333'><td><input type='radio' name='updateid' value='".$rs['ID']."' /></td><td><font face='Verdana' color='#ffcc99'>".$rs['Subject']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Author']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Title']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Extra_Title']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Location']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Publisher']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Pub_Date']."</font></td><td><font face='Verdana' color='#ffcc99'>".$rs['Call_Num']."</font></td><td colspan='2'><font face='Verdana' color='#ffcc99'>".$rs['Des']."</font></td></tr>");
                        echo("<tr bgcolor='#ffcc99'><td colspan='11' height='5'><img src='images/spacer.gif width='1' height='5' alt='' /></td></tr>");
                  }
                  echo("<tr bgcolor='#333333'><td></td><td colspan='9' align='center'><a href='#' onclick='javascript:document.updateDB.submit();'><img src='images/update.gif' alt='' border='0'></a></td><td></td></tr>");
                  echo("</table></form>");
            } else {
                  $sqlUpdate = "select * from Pathfinder where ID = $updateRecord;";
                  $upResults = mysql_query($sqlUpdate);
            
                  echo("<form name='updateDB' action='update.php' method='post'>");
                  echo("<table cellspacing='0' cellpadding='0' border='0' align='center'>");
                  echo("<tr><td width='50'></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='101''></td><td width='50'></td></tr>");
                  echo("<tr><td width='50'><img src='images/tableheader_01.gif' width='50' height='55' alt='' /></td>");
                  echo("<td background='images/tableheader_02.gif' colspan='9'></td>");
                  echo("<td width='50'><img src='images/tableheader_03.gif' height='55' width='50' alt=''></td></tr>");
                  while ($rsUpdate = mysql_fetch_array($upResults)) {
                        echo("<tr bgcolor='#333333'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#ffcc99'>Subject</font></td><td colspan='8' align='center'><textarea name='updateSubject' rows='2' cols='70'>".$rsUpdate['Subject']."</textarea></td><td></td></tr>");
                        echo("<tr bgcolor='#ffcc99'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#333333'>Author</font></td><td colspan='8' align='center'><textarea name='updateAuth' rows='2' cols='70'>".$rsUpdate['Author']."</textarea></td><td></td></tr>");
                        echo("<tr bgcolor='#333333'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#ffcc99'>Title</font></td><td colspan='8' align='center'><textarea name='updateTitle' rows='2' cols='70'>".$rsUpdate['Title']."</textarea></td><td></td></tr>");
                        echo("<tr bgcolor='#ffcc99'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#333333'>Extra Title</font></td><td colspan='8' align='center'><textarea name='updateExtra' rows='2' cols='70'>".$rsUpdate['Extra_Title']."</textarea></td><td></td></tr>");
                        echo("<tr bgcolor='#333333'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#ffcc99'>Location</font></td><td colspan='8' align='center'><textarea name='updateLocation' rows='2' cols='70'>".$rsUpdate['Location']."</textarea></td><td></td></tr>");
                        echo("<tr bgcolor='#ffcc99'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#333333'>Publisher</font></td><td colspan='8' align='center'><textarea name='updatePub' rows='2' cols='70'>".$rsUpdate['Publisher']."</textarea></td><td></td></tr>");
                        echo("<tr bgcolor='#333333'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#ffcc99'>Pub_date</font></td><td colspan='8' align='center'><textarea name='updatePubDate' rows='2' cols='70'>".$rsUpdate['Pub_Date']."</textarea></td><td></td></tr>");
                        echo("<tr bgcolor='#ffcc99'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#333333'>Call No.</font></td><td colspan='8' align='center'><textarea name='updateCall' rows='2' cols='70'>".$rsUpdate['Call_Num']."</textarea></td><td></td></tr>");
                        echo("<tr bgcolor='#333333'><td colspan='2' align='center'><font face='Verdana' size='+2' color='#ffcc99'>Des.</font></td><td colspan='8' align='center'><textarea name='updateDes' rows='2' cols='70'>".$rsUpdate['Des']."</textarea></td><td></td></tr>");
                  }
                  echo("<tr bgcolor='#ffcc99'><td colspan='11' height='5'><img src='images/spacer.gif width='1' height='5' alt='' /></td></tr>");
                  echo("<input type='hidden' name='updateID' value='".$updateRecord."' />");
                  echo("<tr bgcolor='#333333'><td></td><td colspan='9' align='center'><a href='#' onclick='javascript:document.updateDB.submit();'><img src='images/update.gif' alt='' border='0'></a></td><td></td></tr>");
                  echo("</table></form>");
            }
      }
?>

Then when the "Update" button is clicked, the form is submited to the next page, update.php to update the mysql database.
<?
session_start();
if ($_SESSION['loginFailure'] == "true") {
      header("location:admin.php");
} else {
      require("update_mysqlconn.php");
      mysqlUpdate("connection");

      $DB=$_SESSION["Sel"];
      $updateID=$_POST['updateID'];
      $updateSub=$_POST['updateSubject'];
      $updateAuthor=$_POST['updateAuth'];
      $updateTitle=$_POST['updateTitle'];
      $updateExtra=$_POST['updateExtra'];
      $updateLoc=$_POST['updateLocation'];
      $updatePub=$_POST['updatePub'];
      $updatePubDate=$_POST['updatePubDate'];
      $updateCall=$_POST['updateCall'];
      $updateDes=$_POST['updateDes'];
      
                  $sql .= "UPDATE ".$DB." ";
                  if ($DB == "Pathfinder") {
                        $sql .= "SET Subject = '".strtoupper(str_replace("'", "''", $updateSub))."', Author = '".str_replace("'", "''", $updateAuthor)."', Title = '".str_replace("'", "''", $updateTitle)."', Extra_Title = '".str_replace("'", "''", $updateExtra)."', Location = '".str_replace("'", "''", $updateLoc)."', Publisher = '".str_replace("'", "''", $updatePub)."', Pub_Date = '".str_replace("'", "''", $updatePubDate)."', Call_Num = '".str_replace("'", "''", $updateCall)."', Des = '".str_replace("'", "''", $updateDes)."'";
                        $sql .= "WHERE  ID = ".$updateID.";";
                  }
                  if ($DB == "Volunteer") {
                        $sql .= "SET Org = '".str_replace("'", "''", $updateSub)."', Pos = '".str_replace("'", "''", $updateTitle)."', Des = '".str_replace("'", "''", $updateDes)."'";
                        $sql .= "WHERE  ID = ".$updateID.";";
                  }
                  if ($DB == "Links") {
                        $sql .= "SET Resource = '".str_replace("'", "''", $updateSub)."', Link = '".str_replace("'", "''", $updateLoc)."', Extra = '".str_replace("'", "''", $updateExtra)."'";
                        $sql .= "WHERE  ID = ".$updateID.";";
                  }
      
            mysql_query($sql);
      #echo $sql;
      header("location:admin.php?db=update");
}
?>

Does this make any sense to you?
0
 
kcalderAuthor Commented:
Yes I do understand your page. I don't have any issue comprehending the principles associated with interfacing with a database, nor with coding in PHP. I come from a C/C++ background and as an OO language, PHP is very similar in construction to C++. Dreamweaver can be very limiting as both yourself and ingwa and pointed out but sometimes it saves time, and can avoid wheel reinvention. Of course, one can use notepad alone to produce PHP pages if required; that's one of the lovely things about it!

I think that ingwa has highlighted my particular problem. It makes sense that the $_POST array has to see  different values for fields in each record otherwise they cannot be processed in the update procedure. I also agree that my page design is over-complicated, I don't need more than one update button to cover the recordset. It is clear that I cannot make use of DW here but need to code the database interfacing manually. That's not a problem, I have done this on other pages in the website. So, thanks for your assistance; I really appreciate it. In this case, however, I think ingwa shoud be awarded the points.

I am not a professional web developer but a consulting engineer who loves computing and 'dabbles'. From that humble place, may I make a recommendation to you? Using CSS to style your pages and separate style from content will lead to clearer code and provide a vastly more efficient way of maintaining your websites.
0
 
Mark GilbertSenior Performance EngineerCommented:
Hi kcalder, thanks for the points.  I'm happy to hear that I was able to assist you in a way that made sense.  You are right in that DW does speed up the development time greatly when performing mundane tasks such as creating record sets etc but is limited in the amount of control you get using those behaviours when any changes have been made to the behaviour code.  

Re the css recommendation, thank you.  I do use css in all my builds and provide procedural code where explaining concepts or giving solutions to problems.  It's up to the developer to decide whether to use css or not in their own builds.  

Good luck with your project and I'm pleased to know that you are succeeding in achieving what you wanted.  Have a great day.
0
 
kcalderAuthor Commented:
Hi ingwa, the comment about the use of CSS was directed at nplib and not at you given the obfuscation that is occurring in his code as a result of inline styling on HTML tags.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 8
  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now