Subject: Unknown table 'char_main' in MULTI DELETE
Posted By: uniacid Post Date: 4/15/2005 6:16:42 PM
I'm having some trouble and I cannot figure out what is wrong, I am coding the comic site on Ch 9 of Beginning PHP, Apache, MySQL Web Development.

Anyways I checked all the files, this happens when I'm on charedit.php and select delete and then it goes to char_transact.php, I see the error
"Unknown table 'char_main' in MULTI DELETE" I tried looking through to see any obvious mistakes, none found, copied code over from the downloaded source code and I still get the same error, not sure what to do now :/, anyone have any other ideas?

Reply By: BobbyFisher Reply Date: 4/17/2005 4:21:43 AM
Are you sure that the table char_main is in your configured database?

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent
Reply By: uniacid Reply Date: 4/17/2005 1:30:55 PM
Yes, char_main is in the db, I even used the sql config provided

also if it wasn't then the other section of the comic book site would not work
Reply By: BobbyFisher Reply Date: 4/17/2005 4:18:55 PM
Are you using diffrent databases in diffrent parts of the script?  The only way you will get an unknown table is if the table is unknown.  I would check that you are connecting to the correct database at the time that the statment is run.  Run the statment in sql and see what turns up.

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent
Reply By: uniacid Reply Date: 4/18/2005 10:44:29 AM
I believe I am connecting to the correct DB, there is only one database, heres the code I believe it is erroring out on

$sql = "DELETE FROM char_main, char_lair USING char_main m,
   char_lair l WHERE m.lair_id = l.id AND m.id = $cid";
  $result = mysql_query($sql) or die(mysql_error());


Reply By: BobbyFisher Reply Date: 4/18/2005 3:23:36 PM
Sorry, not a clue.  Don't know SQL enough, but I'd say that that statment looks funny to me.  But I can't tell you that it is wrong though.  Have you tried to run that statment in sql manually just to see if the statment is structured correctly.  Just replace $cid with a known value that can be deleated.

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent
Reply By: uniacid Reply Date: 4/18/2005 11:29:31 PM
I'll try but how could it be wrong if its the code supplied in the book, I never saw any error pages for ch 9 either

Reply By: Daniel Walker Reply Date: 4/19/2005 5:37:31 AM
The book may be wrong, and no one may have told the people at Wiley about it, yet. Either that, or they've been told, and just haven't put up an erratum for it, yet: everyone is human. I don't have a copy of the book, so cannot comment on that aspect.

I CAN say that the MySQL DBM is absolutely honest in everything it says. The only reason it ever generates an "Unknown table" error, is because it's not finding a table with that name, as spelt, in the selected database. Simple as that. So there are three possiblities, and only three:
The table name is spelt wrongly in the SQL query
The table has beeen NAMED wrongly in the actual DB
You're in the wrong DB

:)
Reply By: Responder456 Reply Date: 10/13/2006 5:01:06 AM
I had this error and resolved it using the alias name instead of the table name.

SO FOR THE QUERY IN THIS POSTING :-

$sql = "DELETE FROM m, l USING char_main m,
   char_lair l WHERE m.lair_id = l.id AND m.id = $cid";
  $result = mysql_query($sql) or die(mysql_error());

ORIGINAL POSTER'S CODE

$sql = "DELETE FROM char_main, char_lair USING char_main m,
   char_lair l WHERE m.lair_id = l.id AND m.id = $cid";
  $result = mysql_query($sql) or die(mysql_error());

THIS POSTING is a late response (>1year) made due do it appearing in Google at position #1 for "Unknown table in MULTI DELETE".
Reply By: Philippe2 Reply Date: 12/11/2006 3:59:56 PM
Hi,

I am now reading the book and I got the same error as "uniacid".

I used the solution provided by "responder456" and it works (using the alias name of the tables in the DELETE FROM statements instead of the real names of the tables).

This topic is very old, but I still want to confirm the solution provided by "responder456", because I did a search on Google for and "Unknown table" "in MULTI DELETE" mySQL and it led me right on this site (4th result), which is very impressive because I am precisely reading this book and I got the exact same error!

Daniel Walker, the problem is not a problem of table spelling or wrong database, it really is a problem of alias naming. I don't know why the DELETE statement did this kind of error, but I suspect it is because of the MULTI DELETE part. There is a similar bug with MULTI DELETE on mysql.com. Maybe when you do a delete on multiple tables at the same time, you have to use the alias instead of the table names.

Anyway, I am not a SQL pro, but the syntax provided by "responder456" truly works for this particular type of problems, so I hope the folks reading the book and tearing hair off their head will make a good enough search on Google to fall on this page!

Good Luck with all your bugs!


Go to topic 53483

Return to index page 97
Return to index page 96
Return to index page 95
Return to index page 94
Return to index page 93
Return to index page 92
Return to index page 91
Return to index page 90
Return to index page 89
Return to index page 88