Jump to content


PHP -> MSACCESS Update query fails

  • Please log in to reply
No replies to this topic

#1 Cep

  • Members
  • PipPipPip
  • Advanced Member
  • 539 posts
  • LocationOn a boat in the middle of nowhere

Posted 03 August 2006 - 03:55 PM


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?
Thanks Cep

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users