 |
 |
|
 |

01-03-2012
|
 |
Active Member
Company name: Laserdog Productions
|
|
Join Date: Jan 2009
Location: Lafayette, CO
Posts: 856
|
|
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', $categoryID, PDO::PARAM_INT);
$statement->bindValue(':extraName', $extraName, PDO::PARAM_STR);
$statement->bindValue(':extraDescription', $extraDescription, PDO::PARAM_STR);
$statement->bindValue(':extraPrice', $extraPrice);
$statement->bindValue(':extraActive', $extraActive, PDO::PARAM_INT);
$statement->bindValue(':extraValue', $extraValue, PDO::PARAM_STR);
$statement->bindValue(':extraID', $extraID, PDO::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!
|
|

01-03-2012
|
 |
New Member
Company name: WRENDA | WREN Digital Assistans
|
|
Join Date: Sep 2011
Location: Sweden
Posts: 17
|
|
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
|
|

01-03-2012
|
 |
Administrator
Company name: Codehead LLP
|
|
Join Date: Apr 2007
Location: WA
Posts: 175
|
|
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_ERRMODE, PDO::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
|
|

01-03-2012
|
 |
Active Member
Company name: Laserdog Productions
|
|
Join Date: Jan 2009
Location: Lafayette, CO
Posts: 856
|
|
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.
|
|

01-03-2012
|
 |
New Member
Company name: WRENDA | WREN Digital Assistans
|
|
Join Date: Sep 2011
Location: Sweden
Posts: 17
|
|
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
|
|

01-04-2012
|
 |
Active Member
Company name: Laserdog Productions
|
|
Join Date: Jan 2009
Location: Lafayette, CO
Posts: 856
|
|
Re: PHP UPDATE procedure not working
|
PHP Code:
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::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.
|
|

01-05-2012
|
 |
New Member
Company name: WRENDA | WREN Digital Assistans
|
|
Join Date: Sep 2011
Location: Sweden
Posts: 17
|
|
Re: PHP UPDATE procedure not working
Originally Posted by dognose
|
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
|
|

01-05-2012
|
 |
Active Member
Company name: Laserdog Productions
|
|
Join Date: Jan 2009
Location: Lafayette, CO
Posts: 856
|
|
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.
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 11:19 AM.
|
|