0

I am trying to drop a table with php. I have been working with php for a couple of months now, and don't see why I am getting an error. Sample Code:

include 'SQLaccount.php';
$sql = "DROP TABLE RequestBooks;";
if (!$accountCon->query("SET a=1")) {
    printf("Errormessage: %s\n <br> SQL: %s", $accountCon->error , $sql);
}
$accountCon->close();

And this is the error:

Errormessage: Unknown system variable 'a' //What I get when I run theabove code
SQL: DROP TABLE RequestBooks; 

I can drop the table from PHPMyAdmin, and the user I am using has all permissions granted. I use this same query setup for all of my mysql needs, with no problem.

Edit 1:

I was running a query on SET a=1 and not $sql.

include 'SQLaccount.php';
$sql = "DROP TABLE RequestBooks;";
if (!$accountCon->query(**$sql**)) {
    printf("Errormessage: %s\n <br> SQL: %s", $accountCon->error , $sql);
}
$accountCon->close();

Thanks for your help.

5
  • 3
    We will assume you meant ->query($sql) ... nothing to see here Commented Jun 12, 2014 at 4:59
  • 1
    If you are really trying to drop the table, shouldn't if (!$accountCon->query("SET a=1")) be if (!$accountCon->query($sql))?? Commented Jun 12, 2014 at 5:00
  • a is undeclared, perchance? Commented Jun 12, 2014 at 5:01
  • @hd1 I don't even see how a is related here. Commented Jun 12, 2014 at 5:02
  • He's getting the error because a is undeclared... Commented Jun 12, 2014 at 5:04

1 Answer 1

2

Try this

include 'SQLaccount.php';
$sql = "DROP TABLE RequestBooks;";
if (!$accountCon->query($sql)) {
    printf("Errormessage: %s\n <br> SQL: %s", $accountCon->error, $sql);
}
$accountCon->close();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man. I don't know how I missed that when I was going through it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.