PHP script runs but the nothing changes in the MySQL database

Salman A asks:

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 uses a hands-on approach of the major technologies and programming languages to teach readers web development. Providing an understanding of all major aspects of web programming in order to achieve the construction of a database-driven website, the book features state-of-the-art programming languages such as HTML, JavaScript, MySQL, PHP, Apache, Linux/Unix. (Amazon.com, none)

Web Application Design and Implementation: Apache 2, PHP5, MySQL, JavaScript, and Linux/UNIX (Quantitative Software Engineering Series)

(more details)
Web Application Design and Implementation uses a hands-on approach of the major technologies and programming languages to teach readers web development. Providing an understanding of all major aspects of web programming in order to achieve the construction of a database-driven website, the book features state-of-the-art programming languages such as HTML, JavaScript, MySQL, PHP, Apache, Linux/Unix. (Amazon.com, none)

Web Database Applications With Php and Mysql Book [Used]

(more details)
What do eBay, Amazon.com and CNN.com have in common? They're all applications that integrate large databases with the Web. The popularity (and power) of these applications stems from their accessibility and usability: thousands of users can access the... (Glyde, miscellaneous)

PHP MySQL Website Programming: Problem - Design - Solution

(more details)
PHP MySQL Website Programming: Problem - Design - Solution shows the development process for a website using a specific set of technologies: the Apache web server, the MySQL database system, and the PHP scripting language. It gives you a completely hands-on experience and guides you through the construction of a complete application-driven site from design to deployment. Each chapter in the book is broken into three parts: Problem: The authors analyze each task and identify areas that may (Amazon.com, none)

PHP with MySQL Essential Training

(more details)
Website and database assimilation is a necessity for many of today's businesses, and learning to work with PHP is key to integration success. The objective of PHP with MySQL Essential Training is to teach both new and experienced web developers the comprehensive steps for building dynamic, data-driven, interactive websites. Instructor Kevin Skoglund demonstrates the entire process of building a content management system. He starts with the basics of the PHP language (variables, arrays, loops, fu (Amazon.com, none)

PHP and MySQL Training Course by Amazing eLearning

(more details)
Amazing eLearning presents the best self-study training course for PHP and MySQL. This is an instructional training program that offers a quick and easy method for harnessing the vast potential of PHP scripting language, MySQL database and their applications. You will spend your time studying and learning the material by using our sample codes. In addition, your schedule is your own. You can study as quickly or slowly you need to. By the time you are ready to find a better job, launch a new proj (Amazon.com, none)

PHP MySQL Website Programming: Problem - Design - Solution

(more details)
PHP MySQL Website Programming: Problem - Design - Solution shows the development process for a website using a specific set of technologies: the Apache web server, the MySQL database system, and the PHP scripting language. It gives you a completely hands-on experience and guides you through the construction of a complete application-driven site from design to deployment. Each chapter in the book is broken into three parts: Problem: The authors analyze each task and identify areas that may (Amazon.com, none)

PHP and MySQL Manual: Simple, yet Powerful Web Programming (Springer Professional Computing)

(more details)
PHP is becoming the language of choice for Web development, in particular for e-Commerce and on-line database systems. PHP is open source software and easy to install, and with the growth of broadband connections in the home means that more and more people can set up their own personal web servers and create their own on-line applications. Covering all the latest features and functions of PHP including the use of object-oriented programming, this book explains how to use PHP to its full extent. (Amazon.com, none)

MySQL Database Design and Tuning

(more details)
This is the eBook version of the printed book. If the print book includes a CD-ROM, this content is not included within the eBook version.The authoritative, hands-on guide to advanced MySQL programming and administration techniques for high performance is here. MySQL Database Design and Tuning is the only guide with coverage of both the basics and advanced topics, including reliability, performance, optimization and tuning for MySQL. This clear, concise and unique source for the most reliable My (Amazon.com, none)

MySQL Database Design and Tuning (Developer's Library)

(more details)
The authoritative, hands-on guide to advanced MySQL programming and administration techniques for high performance is here. MySQL Database Design and Tuning is the only guide with coverage of both the basics and advanced topics, including reliability, performance, optimization and tuning for MySQL. This clear, concise and unique source for the most reliable MySQL performance information will show you how to: Deploy the right MySQL product for your performance needs. Set up a performance man (Amazon.com, none)

MySQL: Your visual blueprint for creating open source databases

(more details)
* Discusses the basic fundamentals including database terminology and concepts. * Offers an introduction to MySQL and the SQL language, then includes essential tasks to begin using it. * Explores the essentials of MySQL server management, providing a guide for troubleshooting problems. * Presents numerous annotated screenshots, tips and tricks. * Includes a CD-ROM with additional code examples as well as advanced examples using MySQL for UNIX and Windows, PHP for Windows and UNIX, an (Amazon.com, none)

Php And Mysql Web Development Book [Used]

(more details)
We've taken the best and made it even better. The third edition of the best-selling PHP and MySQL Web Development has been updated to include material and code on MySQL 5, PHP 5 and on PHPs object model and validation. Through a clear, practical... (Glyde, miscellaneous)

Pro SQL Server 2000 Database Design: Building Quality OLTP Databases

(more details)
Database design is one of the most contentious issues in computer science. There is always a delicate balance to be struck between the strict academic rules that govern the design of relational databases and the real-world techniques that programmers apply to get the job done in a certain time frame. This book's goal is to cover&emdash;from a "real-world" point of view&emdash;all of the essential elements in designing, modeling, and building efficient relational databases, while avoiding a dry, (Amazon.com, none)

MySQL Administrator's Guide

(more details)
This is the eBook version of the printed book. If the print book includes a CD-ROM, this content is not included within the eBook version. If you are not already one of the 4 million plus users of the MySQL database, you will want to become one after reading this book. MySQL Administrator's Guide is the official guide to installing, administering and working with MySQL 5.0 and MySQL databases. Starting with the basics, you will learn to store, manage and retrieve data in a MySQL database and to (Amazon.com, none)

MySQL Tutorial

(more details)
This is the eBook version of the printed book. If the print book includes a CD-ROM, this content is not included within the eBook version. A concise introduction to the fundamentals of working with MySQL. MySQL is an open-source relational database management system that is rapidly growing in popularity. Known for its speed, reliability, and ease of use, MySQL has proven itself to be particularly well suited both for beginners and for experienced developers to create sophisticated database-back (Amazon.com, none)

MySQL: Essential Skills

(more details)
An introductory look into the most popular open source database. Get step-by-step instruction from installing MySQL, manipulating it, and basic reporting, to advanced reporting, interfacing programs, and backups. An accessible introduction to a powerful database, featuring progress checks, exercises, and Ask the Experts sections in each chapter. (Amazon.com, none)

MySQL Tutorial (All in One)

(more details)
A concise introduction to the fundamentals of working with MySQL. MySQL is an open-source relational database management system that is rapidly growing in popularity. Known for its speed, reliability, and ease of use, MySQL has proven itself to be particularly well suited both for beginners and for experienced developers to create sophisticated database-backed Web sites and applications. MySQL Tutorial is a clear, concise introduction to the fundamental concepts and techniques of working w (Amazon.com, none)

JDBC Metadata, MySQL, and Oracle Recipes: A Problem-Solution Approach (Expert's Voice in Java)

(more details)
JDBC Metadata, MySQL, and Oracle Recipes is the only book that focuses on metadata or annotation-based code recipes for JDBC API for use with Oracle and MySQL. It continues where the authors other book, JDBC Recipes: A Problem-Solution Approach, leaves off. This new edition is also a Java EE 5-compliant book, perfect for lightweight Java database development. And it provides cut-and-paste code templates that can be immediately customized and applied in each developers application development (Amazon.com, none)

NuSphere MySQL Advantage

(more details)
NuSphere MySQL Advantage is a suite of four open-source software packages--proven, popular, and well-supported ones--that work together to run interactive, dynamic Internet sites. Far from just a straight CD-ROM distribution of publicly available software, NuSphere has done a great job of automating the packages' installation processes (the suite installs under both Windows and Linux) so the four utilities interoperate smoothly. You can also install any or all of the suite's components manually, (Amazon.com, none)

MySQL Administrator's Guide and Language Reference, 2/e

(more details)
This is the eBook version of the printed book. If the print book includes a CD-ROM, this content is not included within the eBook version. Written by the creators of MySQL and edited by one of the most highly respected MySQL authors, the MySQL Administrator's Guide and Language Reference is the official guide to installing MySQL, to setting up and administering MySQL databases, and to storing and retrieving data in these databases. This new edition combines into one book the MySQL Language Refer (Amazon.com, none)

High Performance MySQL

(more details)
As users come to depend on MySQL, they find that they have to deal with issues of reliability, scalability, and performance--issues that are not well documented but are critical to a smoothly functioning site. This book is an insider's guide to these little understood topics. Author Jeremy Zawodny has managed large numbers of MySQL servers for mission-critical work at Yahoo!, maintained years of contacts with the MySQL AB team, and presents regularly at conferences. Jeremy and Derek have spent m (Amazon.com, none)

Learning MySQL

(more details)
Whether you're running a business, keeping track of members and meetings for a club, or just trying to organize a large and diverse collection of information, you'll find the MySQL database engine useful for answering questions such as: Which are my top ten fastest-selling products? How frequently does this person come to our facility? What was the highest, lowest, and average score of the team last season? MySQL, the most popular open-source database, offers the power of a relational database i (Amazon.com, none)

High Performance MySQL

(more details)
In High Performance MySQL you will learn about MySQL indexing and optimization in depth so you can make better use of these key features. You will learn practical replication, backup, and load-balancing strategies with information that goes beyond available tools to discuss their effects in real-life environments. And you'll learn the supporting techniques you need to carry out these tasks, including advanced configuration, benchmarking, and investigating logs. (Amazon.com, none)

Practical PHP and MySQL(R): Building Eight Dynamic Web Applications (Negus Software Solutions Series)

(more details)
"Practical PHP and MySQL reflects Jono's commitment to the spirit of making open source subjects accessible to everyone. The book carefully walks you through the code for eight useful, dynamic Web applications. Projects are presented in a playful way, like the forum project that touts horror movies that make you 'hide behind the couch.'"-From the Foreword by Christopher Negus, Series Editor, Negus Live Linux SeriesBuild Dynamic Web Sites Fast, with PHP and MySQL... Learn from Eight Ready-to-Run (Amazon.com, none)

Drupal: Creating Blogs, Forums, Portals, and Community Websites: How to setup, configure and customise this powerful PHP/MySQL based Open Source CMS

(more details)
A complete guide to every aspect of creating a variety of different websites using Drupal. A trove of well-considered and practical information is presented in a logical and intuitive manner so that you can either build up your site step by step by reading from cover to cover or, alternatively, focus on your specific needs by diving into each chapter as required. This book has been written against the latest release v4.7. Drupal is one of the most popular content management systems on the i (Amazon.com, none)

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