Jump to content

Updating a database recordset


Woodstock

Recommended Posts

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));
}

Link to comment
https://forums.phpfreaks.com/topic/186452-updating-a-database-recordset/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.