473,396 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Table updating works only occasionally.

When trying to update a table, the following works only occasionally;
it doesn't work reliably. Can anyone show me where I'm going wrong,
please?

// $commenrts_new is the data from the form ;

$Query="SELECT comments FROM clients WHERE id='$cli_update_id' ";
$Result=mysql_db_query ($DBName, $Query, $Link);
while ($Row=mysql_fetch_array ($Result))
{
$comments_old=$Row[comments];
}
$comments=$comments_old." <br>".$comments_new;
$Query="UPDATE clients SET comments='$comments' WHERE
id='$cli_update_id' ";
$Result=mysql_db_query ($DBName, $Query, $Link);

TIA.
Mar 11 '08 #1
2 1462
On Tue, 11 Mar 2008 08:47:10 +0100, <su****@hotmail.comwrote:
When trying to update a table, the following works only occasionally;
it doesn't work reliably. Can anyone show me where I'm going wrong,
please?

// $commenrts_new is the data from the form ;

$Query="SELECT comments FROM clients WHERE id='$cli_update_id' ";
Where does $cli_update_id come from, and is it sanatised?
$Result=mysql_db_query ($DBName, $Query, $Link);
if(!$Result) echo mysql_error();//or log mysql_error() to a file in case
of a live website
while ($Row=mysql_fetch_array ($Result))
{
$comments_old=$Row[comments];
}
$comments=$comments_old." <br>".$comments_new;
$comments = mysql_real_escape_string($comments);
$Query="UPDATE clients SET comments='$comments' WHERE
id='$cli_update_id' ";
$Result=mysql_db_query ($DBName, $Query, $Link);
Again:
if(!$Result) echo mysql_error();//or log mysql_error() to a file in case
of a live website

I'd say the most likely scenario for failure is a ' in either
$comments_old or $comments_new.

Also: why not do this:

$cli_update_id = mysql_real_escape_string($cli_update_id);
$comments_new = mysql_real_escape_string($comments_new);
mysql_query("UPDATE clients SET comments =
CONCAT(comments,'<br>','$comments_new' WHERE id = '$cli_update_id'");
--
Rik Wasmus
Mar 11 '08 #2
Thank you. I put in some of your code (particularly the escape_string
and the CONCAT bits) and it seems to do the business on all the trials
I've made of it. I'll keep an eagle eye on it throughout the next few
days.

Thanks again.
Mar 11 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hennie de Nooijer | last post by:
Hi, Currently we're a building a metadatadriven datawarehouse in SQL Server 2000. We're investigating the possibility of the updating tables with enormeous number of updates and insert and the...
4
by: dp | last post by:
Anyone have any reason why I can open a table in SQL Enterprise manager, return all rows, and edit the record set, but when I go in through an ADP, connect to the database, and try to edit the same...
4
by: Bonzol | last post by:
..Net 2003, 1.1, Access database. oledb connection Hey there, I had my program updating to the database with a dataset,,, doing things the easy way, binding the dataset to the text box n such,...
2
by: clickon | last post by:
I am confused about the way in which asp:table objects work. When a control is within an asp table it generally appears to be in the scope of the tables parent control. E.g. if i have a page that...
5
by: MN | last post by:
Hello, I have a customer table and another table that I need to prepopulate with special customer IDs, unique and not sequential. Is there a way to configure Access to assign the customer ID to...
4
by: rdemyan via AccessMonster.com | last post by:
My application is calculation intensive and the servers are agonizingly slow. Administrators of my application only update the backends once a month (twice a month max). So, my launching program...
6
by: Hevan | last post by:
Hi, I am using this sql for updating a large table. This sql should update a record like 'abc123'. The first select will return 'abc' and the second select will return '123'. This works fine...
10
by: help4me | last post by:
I am having trouble updating a table. The logic seems so simple but I just can’t get it to work. The table is named test. The column names are passcode, name, address, city, state, zip and email....
4
by: AlexNunley | last post by:
I've adopted a moderately sized (65k records) active use database (Access 2000, Windows XP). One of the most commonly used forms is whats called the RMA generation field, used to add claim...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.