Update a record based on matching field value in form

5 posts by 2 authors in: Forums > CMS Builder
Last Post: December 15, 2011   (RSS)

Re: [gkornbluth] Update a record based on matching field value in form

By Jason - December 15, 2011 - edited: December 15, 2011

Hi Jerry,

In order to not have the query update all records, you need to add a WHERE clause to your update query.

For example, if you wanted to update ALL records with that given activation code, you can try this:

mysql_query("UPDATE `{$TABLE_PREFIX}customer_uploads` SET
email = '".$email."',
first_name = '".$first_name."',
last_name = '".$last_name1."',
street_address = '".$street_address."'
WHERE activation_code = '".mysql_escape($activation_code)."'")

or die("MySQL Error updating Record:<br/>\n". htmlspecialchars(mysql_error()) . "\n");


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Update a record based on matching field value in form

Hi Jason,

I thought I would have to put in a where clause but I kept getting syntax errors every time I tried to put one in.
I'm still getting a syntax error:
MySQL Error updating Record:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE activation_code = 'T87345'' at line 19



Here's the actual code that's generating the error (with or without the load records call):

//load records
list($customer_uploadsRecords, $customer_uploadsMetaData) = getRecords(array(
'tableName' => 'customer_uploads',

));

mysql_query("UPDATE `{$TABLE_PREFIX}customer_uploads` SET

email = '".$email."',
first_name = '".$first_name."',
last_name = '".$last_name1."',
street_address = '".$street_address."',
city = '".$city."',
state = '".$state."',
zip = '".$zip."',

sales_id = '".$sales_id."',
createdDate = NOW(),
updatedDate = NOW(),
createdByUserNum = '0',
updatedByUserNum = '0',
WHERE activation_code = '".mysql_escape($activation_code)."'")
or die("MySQL Error updating Record:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
$userNum = mysql_insert_id();
@saveUploadFromFilepath('customer_uploads', 'uploads', $userNum, '123456789' , $path_of_uploaded_file);
$errors='Thank You<br /><br />Your Portrait Order Has Been Successfully Placed.';
}

?>


ANd I've attached the complete file
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
Attachments:

ordernow3.php 12K

Re: [gkornbluth] Update a record based on matching field value in form

By Jason - December 15, 2011

Hi Jerry,

Try removing the last comma in your field list, the one on this line:

updatedByUserNum = '0',

That should take care of it. I don't know how many times I got caught with that one myself.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Update a record based on matching field value in form

So easy for the Guru

So difficult for the rest of us mere mortals.

Thank you Guru!

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