1
$updateDATA = $con->query("UPDATE table1 SET 
table1.content = table2.content, 
table1.draftid = 0
FROM table1
LEFT JOIN table2 ON table2.id = data_table.draftid 
WHERE table1.id=". $dataID) or die($con);

The above code is outputting this error:

Catchable fatal error: Object of class mysqli could not be converted to string...

I think its because table2.content is a string and its not quoted. I've tried adding 'table2.content' but that didn't work either..... can someone help please?

IF there is a better way of writing that query, I'm up for suggestions as well.

EDIT

I updated my error reporting. or die($con->error);

Its now saying that the issue begins at LEFT JOIN ... telling me to check syntax. Can you do a left join on an update query? Am I formatting it correctly? I've never done this before.

KDJ
  • 309
  • 2
  • 14
  • 1
    `or die($con->error);` , `$con` is an instance of mysqli and cannot be successfully converted into a string.. this may not fix the issue but it will get you to the next stage – Dale Jun 03 '16 at 13:29
  • that did get me further. It is saying that the issue begins at LEFT JOIN.... can you do a left join on an update? Am I formatting this correctly? Never done it before – KDJ Jun 03 '16 at 13:33
  • 1
    You know... I've never tried a join in an update, I don't think it's possible but I'll leave it for a mysql guru to step in :) – Dale Jun 03 '16 at 13:34

2 Answers2

1

The syntax for update with join is a bit different than the one of SELECT.

See here:

UPDATE multiple tables in MySQL using LEFT JOIN

Community
  • 1
  • 1
Josef Sábl
  • 7,538
  • 9
  • 54
  • 66
  • I just had LEFT JOIN after SET instead of before. Moved it and it worked perfectly. Thanks!!! – KDJ Jun 03 '16 at 13:39
0
die() 

expects string to be given as parameter but you pass $con which is mysqli object instead. Write

die($con->error)