I use a separate page to do the addition of information to my DB currently, the whole set of information is being re-written as I type this, but where I am stuck is getting the whole thing to be parsed through then just one line.
The code I currently use is as follows: <SNIP CODE> <!-- modifycart.php -->
$get_Quote = "select st.id, st.sel_item_id, st.sel_item_desc, st.sel_item_price, st.sel_item_qty, st.sel_item_comment from store_shoppertrack as st left join items as si on si.id = st.sel_item_id where session_id = '$PHPSESSID' order by $vsort";
$get_Quote_res = mysql_query($get_Quote) or die(mysql_error());
while ($row = MYSQL_FETCH_ROW($get_Quote_res)) $number = mysql_numrows($get_Quote_res);
if (mysql_num_rows($get_Quote_res) < 1) { //print message $display_block = "<P>You have no items in your Quote. Please <a href=\"seestore.php\">continue to shop</a>!</P>"; } else { //get info and build Quote display
while ($i < $number) { $id = mysql_result($get_Quote_res,$i,'id'); $item_title = mysql_result($get_Quote_res,$i,'sel_item_id'); $item_desc = mysql_result($get_Quote_res,$i,'sel_item_desc'); $item_price = mysql_result($get_Quote_res,$i,'sel_item_price'); $item_qty = mysql_result($get_Quote_res,$i,'sel_item_qty'); $item_comment = mysql_result($get_Quote_res,$i,'sel_item_comment');
if ($item_title == " >>>>>") { $display_block .= "<tr><td>Comment:</td><td colspan=2 align=center><form method=post action=\"replacecart.php\"><input type=\"hidden\" name=\"sel_item_id\" value=\"$item_title\">
You can remove sel_item_id hidden field
<input type=\"text\" size=75 name=\"sel_item_desc\" value=\"$item_desc\">
And rename all other fields to field_name[$id].
Then in replacecart.php loop one of the fields (other then checkboxes if you use them), the array index will give you the id:
foreach($_POST['sel_item_desc'] as $id => $dummy) { update table set sel_item_desc = '$_POST[sel_item_desc][$id]', sel_item_qty = '$_POST[sel_item_qty][$id]', ....... where id = '$id' }
<input type=\"hidden\" name=\"sel_item_qty\" value=\"1\"><input type=\"hidden\" name=\"SESSID\" value=\"$PHPSESSID\">\n<input type=\"hidden\" name=\"id\" value=\"$id\">\n<input type=\"hidden\" name=\"url\" value=\"$_SERVER[PHP_SELF]?view_code=$view_code\"><input type=\"hidden\" name=\"sel_item_price\" value=\"0\"></td><td><select name=\"color\"><option value=\"aqua\">aqua</option><option value=\"black\">black</option><option value=\"blue\">blue</option><option value=\"fuchsia\">fuchsia</option><option value=\"gray\">gray</option><option value=\"green\">green</option><option value=\"lime\">lime</option><option value=\"maroon\">maroon</option><option value=\"navy\">navy</option><option value=\"olive\">olive</option><option value=\"purple\">purple</option><option value=\"red\">red</option><option value=\"silver\">silver</option><option value=\"teal\">teal</option><option value=\"white\">white</option><option value=\"yellow\">yellow</option></select>\n</td><td>Currently: $item_comment</td><td><input type=\"submit\" name=\"submit\" value=\"Modify\"></form></td></tr>\n"; } else { $display_block .= "\n<tr><td><form method=post action=\"replacecart.php\">\n"; $display_block .= "$item_title</td><td><input type=text size=4 name=\"sel_item_qty\" value=\"$item_qty\">\n"; $display_block .= "</td><td><input type=\"text\" size=75 name=\"sel_item_desc\" value=\"$item_desc\">"; $display_block .= "<input type=\"hidden\" name=\"SESSID\" value=\"$PHPSESSID\">\n<input type=\"hidden\" name=\"id\" value=\"$id\">\n<input type=\"hidden\" name=\"sel_item_id\" value=\"$item_title\">\n"; $display_block .= "<input type=\"hidden\" name=\"url\" value=\"$_SERVER[PHP_SELF]?view_code=$view_code\">\n</td><td>"; $display_block .= "<input type=\"text\" name=\"sel_item_price\" size=\"5\" value=\"$item_price\">\n</td><td>\n<input type=\"text\" name=\"comment\" value=\"$item_comment\"></td><td>\n"; $display_block .= "<input type=\"submit\" name=\"submit\" value=\"Modify\"></form></td>\n";
} $i++; }
<!-- End Modify Cart -->
<!-- Replacecart.php -->
$addtocart = "replace into store_shoppertrack values('$_POST[id]','$_POST[SESSID]','$_POST[sel_item_id]','$_POST[sel_item_qty]','$_POST[sel_item_price]','$_POST[sel_item_desc]','$comment', now(),'','','','')";
mysql_query($addtocart);
<!-- End Replace Cart -->
<End Snip CODE>
I have a test set of data and stuff set up on my server: http://lonewolf.homelinux.net/quoter
There are some errors in not getting to other tables, but they are irrelevant for seeing what is there. The data in the table is of course bogus data, but you should see what I am getting at.
Thanks, Robert
Use a SELECT query to get the values (SELECT * FROM table) and a table that has form input fields in the cells. The values for the form fields would be based on the array you get from the SELECT query. The form could be something like <form action="<?=$PHP_SELF ?>" method="post">. In the script, before the body, you would have an if statement to check whether the submit button for the form is set; if it is set, it will run an INSERT INTO query:
if (isset ($submit)) { $query = "INSERT INTO . . . "; $query_result = @mysql_query ($query); }
If the form is submitted, then the values in all the form fields (including any changes) will go into the database. If it's not submitted, the current values will be displayed in the tabled-embedded form. Actually, I think if the form is submitted, it will redisplay with the new values as defaults.
Hopefully this will work, or lead you in the right direction.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php