Jump to content


This topic is now archived and is closed to further replies.


PHP -> MSACCESS Update query fails

Recommended Posts


I have had little luck in finding a decent reference to the SQL syntax needed for each query when using PHP to MS ACCESS.

I have written an update query which I used in one system but for the love of god can't get it to work in a new system I am constructing and it makes absolutely no sense whatsoever.

Here is the code,

function changepassword($user, $oldpass, $newpass) {

      $sql = "SELECT * FROM budgetsys_users WHERE Username = '{$user}' AND Password = '{$oldpass}'";

      $result = odbc_exec(db(),$sql) or die ("SQL Error: Function changepassword - Select users");

      $rowcount = odbc_record_count($result, db(), $sql);

      if ($rowcount==0) {

        $changed = "Invalid Cookie";

      } else {

        $myrow = odbc_fetch_array(odbc_exec(db(),$sql)) or die("SQL Error: Function changepassword - Get user");

        $usr_id = $myrow["UserID"];
        $usr_pass = $myrow["Password"];

        if ($usr_pass==$oldpass) {

            $sql_upd = "UPDATE budgetsys_users SET budgetsys_users.Password = '{$newpass}' WHERE budgetsys_users.UserID = {$usr_id}";
            $upd_result = odbc_exec(db_src(),$sql_upd) or die ("SQL Error: Function changepassword - unable to update user");
            $changed = "Password changed";

        } else {

            $changed = "Incorrect Cookie data";

return $changed;

The code can run the select query, no problem. However it will not run an update. The database has read/write permissions for all users including IUSR (internet guest account).

Knowing from past experience that Access can be funny about the way in which a query is written I started to examine the possibility its something written wrong or missing, but as I have said I have used this query before with no problems yet no matter what tests I try for example putting data directly into the query (instead of using variables) it will not run.

Any ideas?

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.