Jump to content

Update (same page & dynamic) - Textbox-List-View with individual row Edit/Update


momo219

Recommended Posts

So... I have a 2 Table (mysql) Db. Table 1 = (sub)Menu, Table 2 = Images per (sub)Menu.

 

Typical scenario - new.php - loads a form with a MENU ADD form, and a List of current Menus (with Edit and Delete).

 

Edit loads Edit.php, with MENU Edit form (id got from new.php) which lists items per menu_id (T2, images). The row values, (not id's/ pks) are output in TEXT boxes

 

- and My question is how can I make these editable text-box, EDITABLE in their list view, so I can Update on the same page?

...
$result = mysql_query("SELECT * FROM `images` WHERE `imageMenu_id` = '$id' ORDER BY image_position ASC") or trigger_error(mysql_error());
  while($row = mysql_fetch_array($result)){
    foreach($row AS $key => $value) {
      $row[$key] = stripslashes($value);
  }

  // While - - Do this once for each... ie create row and populate per $id (above)...
    echo "<form name ='add_update' action='' method='POST'>";
    echo "<tr>";
      echo "<td valign='top'>" . nl2br( $row['image_id']) . "</td>";
      echo "<td valign='top'>" . nl2br( $row['imageMenu_id']) . "</td>";
      echo "<td valign='top'><input type='text' name='image_name' value='" .stripslashes($row['image_name']) ."'/></td>";
      echo "<td valign='top'><input type='text' name='image_position' value='" .stripslashes($row['image_position']) ."'/></td>";
      echo "<td valign='top'><input type='text' name='image_file' value='" .stripslashes($row['image_file']) ."'/></td>";
      echo "<td valign='top'><input type='submit' value='Update Image' /><input type='hidden' value='1' name='submbit_update' />";
    echo "</tr>";
  echo "</form>";
}
echo "</table>";

I had been trying along the lines of this, but I cant grab the individual row id...

 

if (isset($_POST['submbit_update'])) {
  $sql = "UPDATE `images` SET `image_name`= '{$_POST['image_name']}', `image_position`= '{$_POST['image_position']}', `image_file`= '{$_POST['image_file']}'
  WHERE `image_id` = '$????????'"; // $IMAGEid - cant grab this per UPDATE BUTTON
  mysql_query($sql) or die(mysql_error());
  echo (mysql_affected_rows()) ? "Edited row. " : "Nothing changed. ";
}

 

Key to this is not requiring another page, as I have the T1 list on new and the T2 (per T1 id) list in edit.php

 

Hopefully someone could suggest some refined direction/ suggestions...

 

Many thanks

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.