PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 11th, 2012, 11:23 AM
TomL in VA TomL in VA is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 13 TomL in VA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 37 sec
Reputation Power: 0
Mysql query returns null value

I have code that runs two mysql queries. The second query depends on the result of the first returning true. This works fine, that is to say the value of $result is true and the code moves to the next query. However when the second query runs, which it does and works, it returns a null value for $result.
In testing the code I added some echo statements. The first just shows the value "RESULT". The second, Records deleted showed a -1 value for the affected rows, when in fact one record was deleted. As I said, the both queries work fine.
Can someone tell me why the result value for the second query is null and why the number of record affect = -1?

Thanks,
Tom

$query = DeleteTerm($TermID);
$result = mysql_query($query);
if ($result)
{
$query = DeleteTermFromGroupTermLink($TermID);
$result = mysql_query($query);
echo "RESULT " . $rc . "<br/>";
echo "Records deleted: ", mysql_affected_rows();
if ($result)
{
$lblMessage = "Delete Term Was Successful.";
}
else
{
$lblErrMessage = "Delete Term Encountered An Error. Please Try Again.";
}
}
else
{
$lblErrMessage = "Delete Term Encountered An Error. Please Try Again.";
}

Reply With Quote
  #2  
Old December 11th, 2012, 11:40 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,107 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 3 h 57 m 31 sec
Reputation Power: 1485
You might want to show the two functions you use, assuming they 'contain' the SQL that is run.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
  #3  
Old December 11th, 2012, 11:46 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
1) Please enclose your code in [ PHP ] tags. See the sticky at the top of the forum.
2) You should not be using the MySQL extensions. Switch to PDO and add some error checking.
3) The -1 indicates the previous query failed.
4) If the previous query is really a DELETE then it must return either true or false. You are misinterpreting null for false.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #4  
Old December 12th, 2012, 09:03 AM
TomL in VA TomL in VA is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 13 TomL in VA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 37 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
1) Please enclose your code in [ PHP ] tags. See the sticky at the top of the forum.
2) You should not be using the MySQL extensions. Switch to PDO and add some error checking.
3) The -1 indicates the previous query failed.
4) If the previous query is really a DELETE then it must return either true or false. You are misinterpreting null for false.


Ah, but the query did not fail and there is lies the mystery. The record/s did indeed get deleted. That said, I think I found the problem. The table the from which the record was being deleted had two fields, each a key field (linking table). The delete query passed in a value for only one of the two fields, which was my error. When I corrected the query to pass both key fields as parameters I got a good return code = 1. To be honest I'm still not sure why I got the bad return code. I ran the original code in phpMyadmin and it worked fine.
At this point I can only assume someone up above was tying to let me know what a knucklehead I was not passing in two parameters.

Thanks for you help,
Tom

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Mysql query returns null value

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap