ferret147 Posted February 25, 2011 Share Posted February 25, 2011 I am not much of a hand coder and find the automated option within Dreamweaver very handy for quick app development until tonight when I ran in to a slight problem. I have 1 database table(players) with the following three fields; name imageURL information There are 100 records inserted into this table. I want to list all 100 entries on a page (Which I have done) and then edit each entry on the page so when I submit the page each record is updated instead of me having to update each record individually. I have had a google around and read some articles but still not yet found a solution, below is my current code. <?php require_once('Connections/brackets.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $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_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE players SET imageURL=%s, information=%s WHERE name=%s", GetSQLValueString($_POST['image'], "text"), GetSQLValueString($_POST['info'], "text"), GetSQLValueString($_POST['name'], "text")); mysql_select_db($database_brackets, $brackets); $Result1 = mysql_query($updateSQL, $brackets) or die(mysql_error()); $updateGoTo = "Tournament-Brackets-edit-players.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } mysql_select_db($database_brackets, $brackets); $query_Players = "SELECT * FROM players"; $Players = mysql_query($query_Players, $brackets) or die(mysql_error()); $row_Players = mysql_fetch_assoc($Players); $totalRows_Players = mysql_num_rows($Players); ?> <!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 $editFormAction; ?>" method="POST" name="form1" id="form1"> <table border="1"> <tr> <td>name</td> <td>imageURL</td> <td>information</td> </tr> <?php do { ?> <tr> <td><input type="text" name="<?php echo $row_Players['name']; ?>" value="<?php echo htmlentities($row_Players['name'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td> <td><input type="text" name="<?php echo $row_Players['imageURL']; ?>" value="<?php echo htmlentities($row_Players['imageURL'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td> <td><input type="text" name="<?php echo $row_Players['information']; ?>" value="<?php echo htmlentities($row_Players['information'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td> </tr> <?php } while ($row_Players = mysql_fetch_assoc($Players)); ?> </table> <input type="submit" value="Update Page" /> <input type="hidden" name="MM_update" value="form1" /> </form> </form> </body> </html> <?php mysql_free_result($Players); ?> Everything in the loop words just fine as you would expect it is when it comes to submiting the data that well basically it does not submit the data, I am not a complete wolly and know it is to do with this part of the coding if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE players SET imageURL=%s, information=%s WHERE name=%s", GetSQLValueString($_POST['image'], "text"), GetSQLValueString($_POST['info'], "text"), GetSQLValueString($_POST['name'], "text")); So my question is how do I adjust the small snippet of code above to allow multiple inputs? Quote Link to comment https://forums.phpfreaks.com/topic/228849-dreamweaver-update-multiple-rows/ Share on other sites More sharing options...
ferret147 Posted June 15, 2011 Author Share Posted June 15, 2011 I am still stuck on this if anybody can help me out? Quote Link to comment https://forums.phpfreaks.com/topic/228849-dreamweaver-update-multiple-rows/#findComment-1229975 Share on other sites More sharing options...
PFMaBiSmAd Posted June 15, 2011 Share Posted June 15, 2011 Your form field name="..." attributes are not 'image', 'info', and 'name' for the three input fields, so in the current code, $_POST['image'], $_POST['info'], and $_POST['name'] don't exist and don't have any value. You should be developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors will be reported and displayed. The non-existent $_POST variables would have been pointed out by the resulting error messages. Once you fix the code to work for one set of form fields, you would use array names for the form fields, with the array index value being some identifying value for each row in the database, such as the auto-increment id. See this link - http://us3.php.net/manual/en/faq.html.php#faq.html.arrays Quote Link to comment https://forums.phpfreaks.com/topic/228849-dreamweaver-update-multiple-rows/#findComment-1230074 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.