473,320 Members | 1,949 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,320 software developers and data experts.

Interesting problem

First off, thanks to those who assisted me with the nl2br() issue.

Now here is another interesting "break."

I brought up a record in my edit_task page, didn't make a change, and
hit "submit." Now please forget for a moment the fact that I hit
submit to update a record that hadn't changed...but I received a error
as if MySQL doesn't like making an update to a record when there isn't
a change.

Of course I wanted to check that everything was a normal and by simply
adding another character or line break, it took the change.

Thoughts as to why it wouldn't update a record that wasn't changed?
How would I get around this if/when the client chooses this page,
decides not to update anything, but hits Submit to return to the
previous page???

Thanks.

--Ward
Mar 1 '06 #1
4 1201
On Wed, 01 Mar 2006 14:12:18 -0500, ward@ wrote:
I brought up a record in my edit_task page, didn't make a change, and
hit "submit." Now please forget for a moment the fact that I hit
submit to update a record that hadn't changed...but I received a error
as if MySQL doesn't like making an update to a record when there isn't
a change.


What was the error?

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Mar 1 '06 #2

ward@ wrote:
First off, thanks to those who assisted me with the nl2br() issue.

Now here is another interesting "break."

I brought up a record in my edit_task page, didn't make a change, and
hit "submit." Now please forget for a moment the fact that I hit
submit to update a record that hadn't changed...but I received a error
as if MySQL doesn't like making an update to a record when there isn't
a change.

Of course I wanted to check that everything was a normal and by simply
adding another character or line break, it took the change.

Thoughts as to why it wouldn't update a record that wasn't changed?
How would I get around this if/when the client chooses this page,
decides not to update anything, but hits Submit to return to the
previous page???

Thanks.

--Ward


I bet there are better ways to achieve this, but you could compare the
data in
$_POST against the corresponding data in the DB. if they match, do
nothing.
If they don't match, update it ...

Frizzle.

Mar 1 '06 #3
On 1 Mar 2006 11:33:23 -0800, "frizzle" <ph********@gmail.com> wrote:

Thanks again for the helpo Frizzle.

I believe it's this statement that is causing the error...

if (mysql_affected_rows() == 1) { // If it ran OK.

This is from...

if (mysql_affected_rows() == 1) { // If it ran OK.

// Print a message.
echo '<h1 id="mainhead">Edit aTask</h1>
<p>The task has been edited.</p><p><a
href="edit_task.php">Edit another task?</a><br /><br /></p>';
exit();

} else { // If it did not run OK.
echo '<h1 id="mainhead">System Error</h1>
<p class="error">The task could not be edited due to a system
error. We apologize for any inconvenience.</p>'; // Public message.

echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query .
'</p>'; // Debugging message.

include ('./includes/footer.html');
exit();
}
So I guess this means, since there wasn't a change then the statement
above if FALSE and there for I got the error message.

Now I like your idea so what am I comparing against each other?

I assume an array is created when I hit Submit and thus I'm comparing
the contents of that array with the existing data in the database.

If this is the case, am I comparing the created array with the content
in the page or am I needing to connect to the database and compare the
data there?

Am I even in the ballpark?

Thanks.

Ward

I bet there are better ways to achieve this, but you could compare the
data in
$_POST against the corresponding data in the DB. if they match, do
nothing.
If they don't match, update it ...

Frizzle.

Mar 1 '06 #4
On Wed, 01 Mar 2006 15:02:41 -0500, ward@ wrote:
On 1 Mar 2006 11:33:23 -0800, "frizzle" <ph********@gmail.com> wrote:

Thanks again for the helpo Frizzle.

I believe it's this statement that is causing the error...

if (mysql_affected_rows() == 1) { // If it ran OK.

This is from...

if (mysql_affected_rows() == 1) { // If it ran OK.


MySQL already checks if the updated values match the existing values, and you
get mysql_affected_rows == 0 if they all match.

mysql> insert into t values (1, 'test');
Query OK, 1 row affected (0.00 sec)

mysql> update t set c = 'test' where id = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

mysql> update t set c = 'not test' where id = 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

It's the "Changed:" count that makes it out to PHP.

Don't start doing it yourself by selecting and checking, as you just introduce
race conditions, and MySQL is already doing this for you anyway.

Do check for an actual error through, as in mysql_query() returning false;
_that_ should be flagged up with the error message.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Mar 1 '06 #5

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

Similar topics

56
by: Dave Vandervies | last post by:
I just fixed a bug that some of the correctness pedants around here may find useful as ammunition. The problem was that some code would, very occasionally, die with a segmentation violation...
23
by: Bruno R. Dias | last post by:
Perhaps it would be interesting to program a virtual machine simulating an ancient computer (such as the pdp-7). Then, it would be rather interesting to code for it (porting gcc to it maybe?). I...
7
by: David Sworder | last post by:
Hi, I'm developing an application that will support several thousand simultaneous connections on the server-side. I'm trying to maximize throughput. The client (WinForms) and server communicate...
1
by: Rakesh Roberts | last post by:
I think I have a very interesting cookie problem. I use form authentications on my application. Through out my application I started using a toggle control that persists its value for the session...
2
by: sasifiqbal | last post by:
Hi, One of my developers are facing an interesting problem regarding UserControl invalidation. The problem is: We have two forms in our application. Form A does nothing except loading of...
27
by: Frederick Gotham | last post by:
I thought it might be interesting to share experiences of tracking down a subtle or mysterious bug. I myself haven't much experience with tracking down bugs, but there's one in particular which...
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
5
by: Will Honea | last post by:
I've hit an interesting trap trying to migrate data off an OS/2 server running version 7.2 (fp14) over to 8.2 on Linux. Seems that one table has a column defined in the DDL as "BIGINT NOT NULL...
11
by: onkar.n.mahajan | last post by:
Is it possible to from function call on fly in C programming language ? I am faced with an interesting problem in that I need to take function name and arguments on fly (actually from Database...
4
by: Andrew | last post by:
I am having an interesting namespace conflict. When we use a third party lib we create a company assembly for any descending classes to go in. I have simplified the problem into the example...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.