php - Is something wrong with my query? -


i'm working on database 3 tables, overlapping information. few columns each table can updated user via web app creating. but... there issue. not sure is, updates aren't happening. wondering if wrong query. (actually, after debugging, quite there is).

    if (empty($errors)) {        $query1 = "update owner set             name = '{$name}'         ownerid= '{$ownerid}'";     $query1_result = mysql_query($query1);     if (mysql_affected_rows()==1) {          $query2 = "update queue_acl set                     date_expires = '{$date_expires}'                  user_id='{$ownerid}'";         $query2_result = mysql_query($query2);         if (mysql_affected_rows()==2) {             $query3 = "update ownerorganization set                     orgid = {$orgid}                 ownerid = '{$ownerid}'";             $query3_result = mysql_query($query3);             if (mysql_affected_rows()==3) {                     $_session['name'] = $name;                     $_session['updates_occurred'] = true;             }         }     } 

sorry if trivial; have never worked multiple tables before. any/all suggestions. -n

it's not habit update tables way it. if updates relating somehow might want think creating transaction. transactions make sure updates executed (and if not, rollback done (which means no update executed)):

// disable autocommit  mysqli_autocommit($dblink, false);  // queries $query1 = mysqli_query($dblink, "update owner set name = '{$name}' ownerid= {$ownerid}'"); $query2 = mysqli_query($dblink, "update queue_acl set date_expires = '{$date_expires}' user_id='{$ownerid}'"); $query3 = mysqli_query($dblink, "update ownerorganization set orgid = {$orgid} ownerid = '{$ownerid}'");  if($query1 && $query2 && $query3) {    mysqli_commit($dblink);    $_session['name'] = $name;    $_session['updates_occurred'] = true; } else    mysqli_rollback($dblink); 

i haven't tested guess should work. should take @ mysqli or prepared statements since mysql_ deprecated.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -