Solved

Why is query sometimes not executing

Posted on 2011-02-22
13
396 Views
Last Modified: 2012-05-11
Hi guys

I have this query

$update = "
            UPDATE Users t1 SET
                NewMail =
                    CASE
                        WHEN (NewMail=0 OR NewMail IS NULL) THEN 1
                        ELSE NewMail + 1
                    END
            WHERE
                UserId = $rUserId
            LIMIT 1
        ";
        mysql_query($update);

it is executed with other queries..

IT DOES NOT FAIL.

But sometimes it does not update and the NewMail keeps beeing 0. why is that?
0
Comment
Question by:tim_carter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
13 Comments
 
LVL 15

Expert Comment

by:Aaron Shilo
ID: 34953123
hi

probably becuse you use the LIMIT 1
this means update the last value

change the value to a larger number or remove.
0
 
LVL 1

Author Comment

by:tim_carter
ID: 34953140
It is only 1 user that it should update at this point? why would i run through every record?
0
 
LVL 15

Expert Comment

by:Aaron Shilo
ID: 34953178
just to be clear you need to update only one record at a time ?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:tim_carter
ID: 34953358
YES. it is only one user..

like UserId=2


0
 
LVL 15

Expert Comment

by:Aaron Shilo
ID: 34953395
that isent what i asked.

when you use Userid= 2 will you allways retrive only one row from the table?
0
 
LVL 1

Author Comment

by:tim_carter
ID: 34953416
and that is what i need. but sometimes it does not update the NewMail value
0
 
LVL 15

Expert Comment

by:Aaron Shilo
ID: 34953449
hi
when you run this query

select * from Users
                    where NewMail=0 OR NewMail IS NULL
                     and UserId = $rUserId

notice i removed the LIMIT 1

how meny rows come bac ?
0
 
LVL 1

Author Comment

by:tim_carter
ID: 34953484
what has this query to do with what i want?

1st of the query you have done here will return almost anything because you have not encapsulated (newmail)

MY STATEMENT should update 1 user. and if the user has the value 0 or NULL in newmail it should set the value to 1, else it should add to the current value,.
0
 
LVL 20

Expert Comment

by:Muhammad Wasif
ID: 34953485
>>But sometimes it does not update and the NewMail keeps beeing 0. why is that?
Are you sure that $rUserId is not empty during this time? May be query is failing due to some eorr or $rUserId has incorrect value. Use mysql_error() to detec the error and print the query to debug the issue in this way.

mysql_query($update) or die("Error in Query: $update - ". mysql_error());

Open in new window

0
 
LVL 1

Author Comment

by:tim_carter
ID: 34953557
wasifg

I am already doing that in the script..

It does not fail. And it is randomly it happens.
0
 
LVL 1

Author Comment

by:tim_carter
ID: 34953895
Can it have something to do with CASE?
0
 
LVL 1

Accepted Solution

by:
tim_carter earned 0 total points
ID: 35300046
I found out that sometimes my value was less than zero.
0
 
LVL 1

Author Closing Comment

by:tim_carter
ID: 35331365
less than zero. My own error
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question