Woodstock Posted December 27, 2009 Share Posted December 27, 2009 I'm using Dreamweaver to add and display database records which is working fine. I am having a problem updating a selected record and would appreciate some help here as I have tried endlessly to some minor success. Here is my code which displays a record from the previous page where I have a repeat region showing rows of records. Next to each row I have "edit/update this record?" and when selected, I am taken to this page coded here. I believe my problem is the $updateSQL = sprintf("UPDATE OB_Form SET record=%s WHERE customer=%s", . When I submit this form page after changing the fields, The only field that changes is the "record" field... all the others revert unchanged? So how do I get all the other fields to update? I tried changing the "SET record=%s" to SET (record, customer, phone, address_1, etc) but only got syntax errors? So far, this is ONLY updating the record field? // This displayes the selected row from the the previous page $colname_OB_Form = "-1"; if (isset($_GET['recordID'])) { $colname_OB_Form = $_GET['recordID']; } mysql_select_db(guaranty_outbound); $query_OB_Form = sprintf("SELECT * FROM OB_Form WHERE id = %s", GetSQLValueString($colname_OB_Form, "text")); $OB_Form = mysql_query($query_OB_Form) or die(mysql_error()); $row_OB_Form = mysql_fetch_assoc($OB_Form); $totalRows_OB_Form = mysql_num_rows($OB_Form); // Form1 starts here to update the selected record $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 OB_Form SET record=%s WHERE customer=%s", GetSQLValueString($_POST['record'], "text"), GetSQLValueString($_POST['customer'], "text"), GetSQLValueString($_POST['phone'], "text"), GetSQLValueString($_POST['address_1'], "text"), GetSQLValueString($_POST['city'], "text"), GetSQLValueString($_POST['state'], "text"), GetSQLValueString($_POST['zip'], "text"), GetSQLValueString($_POST['email'], "text")); // code for entering it into a database. mysql_select_db(guaranty_outbound); $Result1 = mysql_query($updateSQL) or die(mysql_error()); $updateGoTo = "Admin.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } Quote Link to comment https://forums.phpfreaks.com/topic/186452-updating-a-database-recordset/ Share on other sites More sharing options...
Woodstock Posted December 28, 2009 Author Share Posted December 28, 2009 Corrected code to read: $updateSQL = sprintf("UPDATE `OB_Form` SET record=%s, customer=%s, phone=%s, address_1=%s, city=%s, state=%s, zip=%s WHERE email=%s", Quote Link to comment https://forums.phpfreaks.com/topic/186452-updating-a-database-recordset/#findComment-984658 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.