PHP script runs but the nothing changes in the MySQL database
Question
I have a script which retrieves the details of a record and uses those details to populate a form for users to amend their details.
The following PHP script is intended to accept the details of the form (assuming some but not necessarily all fields will contain amended data) and then direct users to a success notification page.
$conn = dbConnect('admin');
//create SQL
$sql = 'UPDATE gallery_item SET price = ?, short_desc = ?, height = ?, width = ?, type = ?, long_desc = ? WHERE gallery_id = ?';
$stmt = $conn->prepare($sql);
//execute the query by passing the variables
$done = $stmt->execute(array($_POST['price'], $_POST['short_desc'], $_POST['height'], $_POST['width'], $_POST['type'], $_POST['long_desc'], $item));
//redirect if successful or display error
if ($done)
{
header('Location: http://www.mydomain.com/confirmation_success.php');
exit;
}
else
{
$error = $stmt->errorInfo();
echo $error[2];
}
The script runs without any errors and does in fact direct to a new page.
But when I check the record in the database, nothing has been updated.
I am wondering whether I need to closeCursor() before creating a new PDO object to update the record. Naturally, a database resource was previously created to retrieve the record in the first place.
But where ever I insert $result->closeCursor() it generates a fatal error.
Fatal error: Call to a member function closeCursor() on a non-object.
Answer
You need good debugging skills.
I suggest you start by debugging the data being posted. Add the following line before $done = $stmt... (and make sure to remove them after you are done with debugging):
var_dump( $_POST );
var_dump( $item );
exit( 0 );
These instructions print out the values of the variables and stop the script. Test you page by posting data and double check what $item contains. One possibility is that $item is empty or contains a value that is not present in your database. So, the query executes successfully, but no data would be affected because there is not row matching the $item.
Related Products
Web Application Design and Implementation: Apache 2, PHP5, MySQL, JavaScript, and Linux/UNIX
(more details)Web Application Design and Implementation: Apache 2, PHP5, MySQL, JavaScript, and Linux/UNIX (Quantitative Software Engineering Series)
(more details)Web Database Applications With Php and Mysql Book [Used]
(more details)PHP MySQL Website Programming: Problem - Design - Solution
(more details)PHP with MySQL Essential Training
(more details)PHP and MySQL Training Course by Amazing eLearning
(more details)PHP MySQL Website Programming: Problem - Design - Solution
(more details)PHP and MySQL Manual: Simple, yet Powerful Web Programming (Springer Professional Computing)
(more details)MySQL Database Design and Tuning
(more details)MySQL Database Design and Tuning (Developer's Library)
(more details)MySQL: Your visual blueprint for creating open source databases
(more details)Php And Mysql Web Development Book [Used]
(more details)Pro SQL Server 2000 Database Design: Building Quality OLTP Databases
(more details)MySQL Administrator's Guide
(more details)MySQL Tutorial
(more details)MySQL: Essential Skills
(more details)MySQL Tutorial (All in One)
(more details)JDBC Metadata, MySQL, and Oracle Recipes: A Problem-Solution Approach (Expert's Voice in Java)
(more details)NuSphere MySQL Advantage
(more details)MySQL Administrator's Guide and Language Reference, 2/e
(more details)High Performance MySQL
(more details)Learning MySQL
(more details)High Performance MySQL
(more details)Practical PHP and MySQL(R): Building Eight Dynamic Web Applications (Negus Software Solutions Series)
(more details)Drupal: Creating Blogs, Forums, Portals, and Community Websites: How to setup, configure and customise this powerful PHP/MySQL based Open Source CMS
(more details)Related Articles
- Php Development Is Becoming Increasingly Popular
PHP simply refers to Hypertext Preprocessor and is becoming quite popular due to the wide nature of functions that it can be used for. Also, PHP development is relatively simple for newcomers to lea - Security Hole Mail Header Injection At Php
If you use PHP language to send an email (especially if using HTML form), you must take extra precautions. In the last few weeks, many have tried actively exploiting PHP scripts that use mail() func - Introduction To Web Services With Php
Note that both Google's service and PEAR::SOAP are technically still in beta, so you might encounter the odd bug from time to time. There are other SOAP client libraries available, including the PHP - At A Glance: Asp.net Vs. Php
In the world of web development, the choice of which development language to use commonly comes down to two popular choices. Web applications, specifically those relying on back end databases, are t - PHP and LAMP Software
PHP is the most widely used web scripting language. It enables even relatively inexperienced programmers to develop dynamic web sites for virtually any web application under the Sun (this is an insi - How To Speed Up A Database Which Has Gotten Slow
Preface While the actual database design usually is able to handle the amount of stored data without major performance problems newly added clients and their data volume changes that. Once the s - Database A Boon For It
The advent of the database is perhaps the most valuable thing that has come out of the computer age. The power of information brought to us in every increasing speeds and volumes has increased our a - Strengthen Your Website Content With Online Database Access
Website content, as articles, has taken center stage as web publishers scramble to differentiate their online offers. As both the quantity and quality of articles have accelerated, so too have onlin - The Value Of An Oracle Database
There are some very large, very powerful companies out there that have saved quite a bit of money using an Oracle database. Will your company be one of those? Or, will you simply overlook this oppor - Apartment Locators Or Apartment Database Sites – Which Is The Best For You?
When you do a search on a Search Engine for "apartments" you are going to come across two types of Website resources; apartment locator sites and apartment database sites. Which is the best for you? - Relational Database Management System In Sap
Basically SAP, an enterprise application is made up of programs together with the data used and formed by programs. The data are organized in a meaningful way within the database, making it easy for - Tips to Build Your Email Address Database
WHY BUILD YOUR EMAIL ADDRESS DATABASE? Gaining your customers' email addresses will: Provide an additional channel for reaching your customers Increase the ROI of your marketing investmen - Building A Database Is Easier Than You Think
Fifteen years ago, we attended a one day seminar given by my good friend, Ken Erdman. Ken was a savey direct marketer and my company was an industrial sales company selling specialized widgets. We s - Sql Server Stored Procedures
"SQL Server Stored Procedures Stored Procedures are SQL statements saved in a database as a n object. They can be called interactively through the Query Analyzer, and by other stored procedures. T - Understanding Sql Web Hosting
What is SQL Web Hosting Before understanding the concept of SQL web hosting, it’s necessary to have a basic grasp on what SQL is, and also how web hosting works. * SQL is the acronym for S - Great Plains Customization - Sales Document Delivery by SQL Mail
Microsoft Dynamics GP or former Great Plains eEnterprise and Dynamics have multiple options for modification, integration, programming and reporting. In this small publication we would like to show - Crystal Reports - Microsoft SQL Server
Microsoft SQL Server is the leader for inexpensive and middle size SQL solutions. Plus it is now capable to serve large enterprise on Microsoft Windows platform. Crystal Reports is the most flexib - Changing The Way We Think About Change - How Does Viral Change (TM) Work?
Under certain conditions, a small set of behaviours has the power to create significant and sustainable change in the organization. This statement - crucial to understanding the type of management o - Changes, Changes, and More Changes!
As in Real Life changes appear and they are either expected, unexpected or they can be orchestrated and planned. Some changes are good, some not so good, and some down right painful.When Museum was - They’re Not Called “prescriptions” For Nothing. Chronic Pain.
I lost a beloved relative last year. I’m not going to say who she was because I am going to say some unkind things about her. That doesn’t mean I didn’t love her, but it was often difficult to - What Does Your Doctor Really Mean When He Says “there’s Nothing Wrong”?
What thoughts go through your mind when you hear this - “There’s nothing wrong.” Most likely you hear that the crappy way you’re feeling is all in your head - or so the doctor thinks. - Who Do You Blame If They Learn Nothing At Your Seminar?
Ted, Alice, Pete and Rita are all attending the same seminar. They all expect to learn something, after all that's why they are there. Trouble is they each have very individual and different ways of - The Power Of Doing Nothing For Chronic Pain Relief
Do we really NEED to DO in order to get relief from chronic body pain, or is there an alternative? Nearly every pain relief technique has been developed based on a philosophy that it can only b - Mini-stroke: A Term That Means Everything And Therefore Nothing
What is a "mini-stroke?" Doubtlessly, you've heard someone use this term before, and you might have even seen it in print. What does this term mean to you? Probably something less than a full-fledge - Allergy Season: It's Nothing To Sneeze At
Almost 40 million Americans face seasonal allergies, which usually begin in the spring and can last through the first frost. They're often triggered by pollens, molds or other airborne allergens. Ac
Related Questions
- What's the best way to show limited records using PHP from a MySQL database like Yahoo! does in my mailbox?
- How do you import data from an oracle database into a mysql database?
- PHP and MYSQL newbie question!?
- How to overwrite / update a previous record automatically in mySQL?
- MySQL and Coldfusion Error?
- PHP : how do i redirect a page using PHP Script?
- Which is the best for implementation of a database driven website ? php5 or ASP.NET ?
- Which is the best for implementation of a database driven website ? php5 or ASP.NET ?
- what are the requirements for doing Microsoft Certified Database Administrator (MCDBA) on Microsoft SQL Server
- I am looking for work experience / placement in SQL database admin roles.I am ready to work anywhere in UK.?
- Is 47 too old to be a SQL a Server Database Administrator?
- How to create a log on system with security features in vb6.0 and sql server or ms access database.Amkila?
- Can I make Oracle to automatically trigger SQL Server to run an sql command?
- how do i use PHP script to calculate the shipping prices on my website?
- php script.... how to parse a url?
- PHP script fpr mileage tracking?
- why wont this php script redirect me?
- How do I redirect within this PHP script?
- Url redirect that imputs the url into the php script?
- php script for storing username and password and redirecting user to other page?
- i learned i can change eye color from color contacts. can i wear them if i have nothing wrong with my vision?
- I've been using bio oil for bout 2months now and nothing seems to have changed? Why?
- Question about the players who changed the game possibly changing it for the bad, in the long run.?
- How do you change your run if you run weird?
- Professional script to run free / paid web hosting company?






















