Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Update multiple records on one page php/mysql

Participant ,
Jun 04, 2010 Jun 04, 2010

Hi folks,

I am trying to adapt a page to offer the option to update multiple records on one page.

The intention is to edit FAQ categories which are contained in a table with just two fields - the category and an id.

The page lists each categories in a form with a submit button which is then repeated for each record in the recordset.

Unfortunately my plan didn't work and only the first record updates as intended.

Can anyone suggest how I can make it work?

Here's the code I have so far.

************** The Update Code *****************

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

if (!isset($mm_abort_edit) || !$mm_abort_edit) {

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {

  $updateSQL = sprintf("UPDATE faq_categories SET category=%s WHERE id=%s",

                       GetSQLValueString($_POST['category'], "text"),

                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_con_mysite, $con_mysite);

  $Result1 = mysql_query($updateSQL, $con_mysite) or die(mysql_error());

  $updateGoTo = "faq-category-edit.php

  if (isset($_SERVER['QUERY_STRING'])) {

    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

    $updateGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $updateGoTo));

}}

************** Update Code Ends *****************

************** The Form *****************

<form name="frm_editcategory" id="frm_editcategory" method="POST" action="<?php echo $editFormAction; ?>">

  <?php do { ?>

<fieldset>

          <input name="id" type="hidden" value="<?php echo $row_rs_faqcategory['id']; ?>" />

          <input name="category" type="text" class="formrightcolumn"  value="<?php echo $row_rs_faqcategory['category']; ?>" />

          <input name="save" type="submit" class="submitbutton" id="save" value="save" />

</fieldset>

          <input type="hidden" name="MM_update" value="form1" />

   <?php } while ($row_rs_faqcategory = mysql_fetch_assoc($rs_faqcategory)); ?>

</form>

************** The Form Ends *****************

Cheers

Dave

TOPICS
Server side applications
871
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2010 Jun 18, 2010

Surely someone must be able to figure this out?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 18, 2010 Jun 18, 2010
LATEST

What does debugging tell you? What's the value of each of the variables? Did you try using regular echo statements to monitor what's going on? That's what I always do whenever I am stuck in my PHP coding.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines