Problem with Update

Discussion in 'PHP' started by zed420, Nov 2, 2008.

  1. #1
    Hi ALL
    Can anyone help me on this query please, all I'm trying to do is Update three tables in a same query.

    		if($_POST['submit']) {
    		foreach($_POST as $job_id) { 
    		mysql_query("UPDATE job_tb,blockbook,blockbook2 SET 
    		job_tb.cust_address = 'Cancel' 
    		blockbook.cust_address = 'Cancel'
    		blockbook2.cust_address1 = 'Cancel'
     		WHERE job_tb.job_id = '$job_id'
    		AND blockbook.job_id = '$job_id' 
    		AND blockbook2.job_id = '$job_id'"); 
    		if (mysql_affected_rows() > 0) { // execute query 
        	print "<font color=red size=2> No. = $job_id has been Updated</font><p>"; 
      		} 
    	}
    }
    
    Code (markup):
    Thanks
    Zed
     
    zed420, Nov 2, 2008 IP
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #2
    try if this works?

     
    ads2help, Nov 2, 2008 IP
  3. zed420

    zed420 Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    Thanks for replying but NO joy its still the same.

    Thanks
    Zed
     
    zed420, Nov 2, 2008 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    I've never update 3 tables at a time so i do not know if the syntax is correct. try doing web search about it
     
    ads2help, Nov 2, 2008 IP
  5. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #5
    you are using a join statement but you have not join the tables yet
     
    javaongsan, Nov 2, 2008 IP
  6. zed420

    zed420 Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    This is error message I'm getting

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'blockbook.cust_address = 'Cancel' blockbook2.cust_address1 = 'Cancel' W' at line 3

    But I still can not see anything wrong with syntax, Please help!!!
    Thanks
    Zed
     
    zed420, Nov 3, 2008 IP
  7. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #7
    like java said. Use mysql join function. I think i saw some topics about that when i did a web search just now
     
    ads2help, Nov 3, 2008 IP
  8. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #8
    UPDATE job_tb,blockbook,blockbook2 SET
    job_tb.cust_address = 'Cancel' ,
    blockbook.cust_address = 'Cancel',
    blockbook2.cust_address1 = 'Cancel'
    WHERE job_tb.job_id = '$job_id'
    AND blockbook.job_id = '$job_id'
    AND blockbook2.job_id = '$job_id'"


    You are missing the , coma between the update variables.
     
    javaongsan, Nov 3, 2008 IP
  9. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #9
    I mentioned that too but its not working..
     
    ads2help, Nov 3, 2008 IP
  10. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #10
    Why not split it into 3 statement?
     
    javaongsan, Nov 4, 2008 IP