Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8941369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:16:58+00:00 2026-06-15T11:16:58+00:00

Simply, I would like to truncate then delete a table from a database in

  • 0

Simply, I would like to truncate then delete a table from a database in mysql as follows :

require_once('connect_m.php');

if(isset($_POST['del'])){
    if(is_array($_POST['del'])) {
        foreach($_POST['del'] as $value){
            $query = "TRUNCATE TABLE ".$value."";
            $result = mysql_query($query);
            if(!$result){
                echo "Wrong";
            }
            $query2 = "DROP TABLE ".$value."";
            $result2 = mysql_query($query2);
            if(!$result2){
                echo "Wrong2";
            }
        }

As for connect_m.php its simply establishing mysql connection

<?php
$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("stores_m", $con);

?>

However I’ve echo the $value and I got the correct value needed (correct table names), but the code does not truncate or delete any selected table! And the most annoying part is that there are no warning or error messages either for php/mysql.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:17:00+00:00Added an answer on June 15, 2026 at 11:17 am

    You need to remove the quotes around your table name for TRUNCATE and DROP to work

    Instead of echoing “error” you should display the real error returned by MySQL that would help you understand what happens:

    $result2 = mysql_query($query2);
    if(!$result2){
        echo "Error '" . mysql_errno() . "' : " . mysql_error();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i simply would like to know from who has well documented about, if i
I would simply like to know if it is possible to load tumblr posts
i would like a simple help... i have a url like this: example.com/profile.php?id= &
I have a table in a MySQL database that I am running simple SELECT
I simply would like to display icon that is in fixed location in MapView.
I would like to create a little game where user would simply move some
Using Castle.DynamicProxy, I simply would like to get an Interface-Proxy-Without-Target, but... With a default-constructor
I would simply like to create a file that stays around after the program
Plain and simple issue: I would like to annotate my method parameter with some
I have a simple issue -- I would like to check a field to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.