Website Coding

Stuck on a line of code? Find resources and post your coding questions here.

Forum Sponsor (Advertise with us)
Reply
 
Thread Tools Display Modes
    #1 (permalink)  
Old 01-03-2012
dognose's Avatar
Active Member
Company name: Laserdog Productions
 
Join Date: Jan 2009
Location: Lafayette, CO
Posts: 856
Default PHP UPDATE procedure not working
The app is a tinker project of mine. It's a pizza shop & this segment is the content management system where the owner can INSERT & UPDATE menu items. I've got INSERT working fine, but can't get UPDATE to work. I don't get errors, but it doesn't update the record.

Calling code:
PHP Code:
edit_extra($category_id$itemName$itemDescription$itemPrice$itemActive$itemValue$extra_id); 
In debug I can see there are correct values for all variables.

Update code:

PHP Code:
 function edit_extra($categoryID$extraName$extraDescription$extraPrice$extraActive$extraValue$extraID) {
    global 
$db;
    
$query 'UPDATE menuitems
              SET CategoryID = :categoryID,
                  Name = :extraName,
                  Description = :extraDescription,
                  Price = :extraPrice,
                  Active = :extraActive,
                  Value = :extraValue,
              WHERE ItemID = :extraID'
;
    try {
        
$statement $db->prepare($query);
        
$statement->bindValue(':categoryID'$categoryIDPDO::PARAM_INT);
        
$statement->bindValue(':extraName'$extraNamePDO::PARAM_STR);
        
$statement->bindValue(':extraDescription'$extraDescriptionPDO::PARAM_STR);
        
$statement->bindValue(':extraPrice'$extraPrice);
        
$statement->bindValue(':extraActive'$extraActivePDO::PARAM_INT);
        
$statement->bindValue(':extraValue'$extraValuePDO::PARAM_STR);
        
$statement->bindValue(':extraID'$extraIDPDO::PARAM_INT);
        
$statement->execute();
        
$rowct $statement->rowCount();
        
$statement->closeCursor();

    } catch (
PDOException $e){
        
// do something here
        
$error_msg $e->getMessage();
    }

Again, in debug I can see correct values in the parameters in the SET clause, but nothing happens. $rowct = 0

Thanks for any help or suggestions!
__________________
Lezly Harrison
Laserdog Productions - Code that Doesn't Bite
Reply With Quote
    #2 (permalink)  
Old 01-03-2012
wrenda_va's Avatar
New Member
Company name: WRENDA | WREN Digital Assistans
 
Join Date: Sep 2011
Location: Sweden
Posts: 17
Send a message via Skype™ to wrenda_va
Default Re: PHP UPDATE procedure not working
Hi!
Have you tried to run the query directly in MySQL w dummy values?
Have you ensured proper rights settings is granted?

//Ann
__________________
WRENDA | WREN Digital Assistans www.wrenda.se
~love to help and learn~ Keep up the good work! /Ann
Reply With Quote
    #3 (permalink)  
Old 01-03-2012
Codehead's Avatar
Administrator
Company name: Codehead LLP
My latest blog post: Mac Performance Benchmark App
 
Join Date: Apr 2007
Location: WA
Posts: 175
Default Re: PHP UPDATE procedure not working
Hi,

Please try to add this to your code (after creating this $db) and see if PDO throws any exceptions for your query:

PHP Code:
$db->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION); 

Also you are not doing anything with the exception, at least in this piece of code, a function like this should do something like:

PHP Code:
function ...
   ...
   } catch (
PDOException $e) {
        throw new 
Exception($e->getMessage());
    } 


So the client can catch the exception and make sure it worked fine, you could let the client catch the PDO exception directly but this way you can abstract away that part from the client...
__________________
"Imagination is more important than knowledge."
Albert Einstein
Reply With Quote
    #4 (permalink)  
Old 01-03-2012
dognose's Avatar
Active Member
Company name: Laserdog Productions
 
Join Date: Jan 2009
Location: Lafayette, CO
Posts: 856
Default Re: PHP UPDATE procedure not working
Ann, I went back to check it with dummy values, since the last time I did that was a bit ago & it was a syntax error - an extra comma directly before the WHERE clause. I've made so many changes to this code I didn't even see it.

And yeah, I don't have any error handling in my code right now.

Thanks guys.
__________________
Lezly Harrison
Laserdog Productions - Code that Doesn't Bite
Reply With Quote
    #5 (permalink)  
Old 01-03-2012
wrenda_va's Avatar
New Member
Company name: WRENDA | WREN Digital Assistans
 
Join Date: Sep 2011
Location: Sweden
Posts: 17
Send a message via Skype™ to wrenda_va
Default Re: PHP UPDATE procedure not working
Lezly, I do that ALL the time, I have a stupid user in me to whom I sometimes must talk some sense Have I had the trained eye I would have picked that up, but not tonight, have been working long hours.

Glad it got solved, and an error handling is useful, the try-part doesn't do a neatly trick without.
__________________
WRENDA | WREN Digital Assistans www.wrenda.se
~love to help and learn~ Keep up the good work! /Ann
Reply With Quote
    #6 (permalink)  
Old 01-04-2012
dognose's Avatar
Active Member
Company name: Laserdog Productions
 
Join Date: Jan 2009
Location: Lafayette, CO
Posts: 856
Default Re: PHP UPDATE procedure not working
PHP Code:
$db->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION); 
That has been helpful with some other db issues, as well!

Ann, one day I had a slew of red lines in one procedure & for the life of me I couldn't see what the problem was. I took a break, came back & immediately saw that I had used SQL's @ symbol instead of PHP's $ symbol for all my variables.
__________________
Lezly Harrison
Laserdog Productions - Code that Doesn't Bite
Reply With Quote
    #7 (permalink)  
Old 01-05-2012
wrenda_va's Avatar
New Member
Company name: WRENDA | WREN Digital Assistans
 
Join Date: Sep 2011
Location: Sweden
Posts: 17
Send a message via Skype™ to wrenda_va
Default Re: PHP UPDATE procedure not working
Originally Posted by dognose View Post

Ann, one day I had a slew of red lines in one procedure & for the life of me I couldn't see what the problem was. I took a break, came back & immediately saw that I had used SQL's @ symbol instead of PHP's $ symbol for all my variables.
That's typically me as well, but I'm still learning the ropes when enough is enough and it's time to take a break. It's very nonproductive to spend hours on a syntax and then when you take a fresh look at it it's so simple and obvious.
__________________
WRENDA | WREN Digital Assistans www.wrenda.se
~love to help and learn~ Keep up the good work! /Ann
Reply With Quote
    #8 (permalink)  
Old 01-05-2012
dognose's Avatar
Active Member
Company name: Laserdog Productions
 
Join Date: Jan 2009
Location: Lafayette, CO
Posts: 856
Default Re: PHP UPDATE procedure not working
The upside to walking away for a few minutes - something gets down around the house - a load of laundry, those dishes setting in the sink.
__________________
Lezly Harrison
Laserdog Productions - Code that Doesn't Bite
Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Virtually There ZA Business Development 13 09-05-2011 02:18 PM
How the **** do I update from Wordpress 2.1 MondayMorn General Website Design and Development 4 02-16-2010 07:03 PM
What is your usual procedure with clients? KC Virtual Solutions New Client Best Practices 19 12-02-2009 07:49 PM
Update my PC or just get a new one? theessentialva Computer Hardware and Office Supplies 15 02-07-2009 12:34 PM


All times are GMT -4. The time now is 11:19 AM.

International Virtual Assistants Association
Project Management for Virtual Assistants
Work from Home | Become A Virtual Assistant
Virtual Assistant Directory
Affordable Logo Design
Virtual Assistant Contracts
Virtual Assistant Forums Advertising

© Virtual Assistant Forums 2012
All content and images are protected under copyright law and may not be reproduced in any way without express written consent.