/    Sign up×
Community /Pin to ProfileBookmark

Mysql Error

Hi, i am gettin this mysql error with this code, does any 1 know why

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 ”” at line 1

[code=php]
$num = 0;
$show = “SHOW TABLES”;
$show_res = mysql_query($show,$conn) or die(mysql_error());
while($row = mysql_fetch_assoc($show_res)) {
$sql = “DROP TABLE ‘”.$row[$num].”‘”;
mysql_query($sql) or die(mysql_error());
$num++;
}
[/code]

It should list all the tables and then drop them all

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@Brandoe85Nov 19.2004 — I don't think it's suppose to have the single quotes around the table name maybe try this:
[code=php]
$num = 0;
$show = "SHOW TABLES";
$show_res = mysql_query($show,$conn) or die(mysql_error());
while($row = mysql_fetch_assoc($show_res)) {
$sql = "DROP TABLE ".$row[$num].;
mysql_query($sql) or die(mysql_error());
$num++;
}
[/code]

Also...look [URL=http://dev.mysql.com/doc/mysql/en/DROP_TABLE.html]here[/URL]
Copy linkTweet thisAlerts:
@k0r54authorNov 19.2004 — Sorry yes you are right but i now get an error saying unexpected ; on line 10

which is $sql = "DROP TABLE ".$row[$num].;

i put in $sql = "DROP TABLE ".$row[$num].""; and i get another error ????


whats wrong with it :eek:
×

Success!

Help @k0r54 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...