Trying to update a field in every record inside a mysql table

Posted on 2007-10-13
Last Modified: 2013-12-13
I have the following code thats scrolls through okay but doesn't update the table

$query="SELECT ordID, sw_accno, ordZip, ordAddress FROM orders ORDER BY ordID DESC";
$result = mysql_query($query, $dbh) or die(mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

      $orderID = $ordID;
      $fullacount = $ordZip . $ordAddress;
      $fullacount_nospace = str_replace (" ", "", $fullacount);
      $fullacount_trimmed = strtoupper(substr($fullacount_nospace, 0, 10));

      $sql = "UPDATE orders SET sw_accno = '$fullacount_trimmed' WHERE ordID = '$orderID';";
      echo "<br>ID = " . $ordID . " updated to  = " . $fullacount_trimmed;
Question by:samkay
    LVL 28

    Accepted Solution

    Do you get an error message of some sort?
    LVL 20

    Assisted Solution

    echo $sql
    it will return update query so that u will see is it correct or not

    Author Comment

    sorry - false alarm -  the data has been updated but the database connection info was pointing to the wrong copy of the database :)

    Author Comment

    thanks for looking though! I have split the points

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now