Errors when modifying Record Update form code

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 28, 2019   (RSS)

By daniel - January 28, 2019

Hi Jerry,

The correct usage of the mysql_update() function is:

mysql_update($tableName, $recordNum, $customWhere, $colsToValues);

Since you're using the record's email rather than num to update, you'll want to use null for the $recordNum, and pass the email to $customWhere.

mysql_update($tableName, null, ['email_address' => $email], $colsToValues);

Hope that helps! Let me know if you have any other questions.

Thanks,

Daniel
Technical Lead
interactivetools.com

By gkornbluth - January 28, 2019

Thanks Daniel,

I understand it better now and got it working with a few modifications.

For anyone who has the same concerns, here's what I used for the update record code:

<?php $where = "email_address = '$email_address'"?>
<?php
$tableName = 'publcity_listings';
$colsToValues = array();
$colsToValues['first_name'] = $_REQUEST['first_name'];
$colsToValues['last_name'] = $_REQUEST['last_name'];
$colsToValues['email_address'] = $_REQUEST['email_address'];
$colsToValues['street_address'] = $_REQUEST['street_address'];
$colsToValues['city'] = $_REQUEST['city'];
$colsToValues['state'] = $_REQUEST['state'];
$colsToValues['zip'] = $_REQUEST['zip'];
$colsToValues['phone'] = $_REQUEST['phone'];
$colsToValues['cell'] = $_REQUEST['cell'];
$colsToValues['description'] = $_REQUEST['description'];
mysql_update($tableName, null, $where, $colsToValues);
?>

<?php

// on success
$first_name = @$_REQUEST['first_name'] ;
$last_name = @$_REQUEST['last_name'] ;
$_REQUEST = array(); // clear the form values
$errorsAndAlerts = "The contact information for $first_name $last_name has been updated.<br>You can now enter another email address.";

And here's what I used for the insert record code:

$tableName = 'publcity_listings';
$colsToValues = array();
$colsToValues['createdDate='] = 'NOW()';
$colsToValues['updatedDate='] = 'NOW()';
$colsToValues['createdByUserNum'] = 0;
$colsToValues['updatedByUserNum'] = 0;
$colsToValues['first_name'] = $_REQUEST['first_name'];
$colsToValues['last_name'] = $_REQUEST['last_name'];
$colsToValues['email_address'] = $_REQUEST['email_address'];
$colsToValues['street_address'] = $_REQUEST['street_address'];
$colsToValues['city'] = $_REQUEST['city'];
$colsToValues['state'] = $_REQUEST['state'];
$colsToValues['zip'] = $_REQUEST['zip'];
$colsToValues['phone'] = $_REQUEST['phone'];
$colsToValues['description'] = $_REQUEST['description'];
$userNum = mysql_insert($tableName, $colsToValues, true);

// On Success
$first_name = $_REQUEST['first_name'];
$last_name = $_REQUEST['last_name'] ;
$_REQUEST = array(); // clear form values
$errorsAndAlerts = "A record for $first_name $last_name has been successfully created.<br>You can now enter another email address.";

All of the $_REQUEST fields reference fields in the insert/update form.

There's a much more complete recipe in the CMSB Cookbook.

Best,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php