Delete all rows from mySQL table in PHP
Try this code:
<form>
<input type="submit" class="button" name="delet" id="delet" value="DELETE WHOLE DATA"/>
</form>
<br></br>
<?php
if(isset($_GET['delet'])){
$connection = mysqli_connect('localhost', 'root', 'root', 'testlo');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sql = 'DELETE FROM tbl_fordelete';
$sql1=mysqli_query($connection, $sql);
if ($sql1) {
echo "Database dqqwewrw was successfully dropped\n";
} else {
echo 'Error dropping database: ' . mysql_error() . "\n";
}
$connection->close();
}
Clear table values with PHP
Use TRUNCATE table_name
. It will wipe all data but leave the structure intact.
Delete all rows from MySQL table using PHP
Try to print something in your IF statement, to check if the code pass through.
If not, try adding in your form:
<input type='hidden' name='flag' value='pass'>
Then changes your IF in this way:
if ($_POST['flag'] == "pass") {
}
clear all the entries from a table with php
This is a typo. You used mysql_query()
instead of mysqli_query()
. Change
mysql_query($sql);
to:
mysqli_query($con, $sql);
Also note that the param lists of both functions differ. mysqli_expects()
a connection handle as it's first param.
delete entire table
If you need to delete all records from the table - then just omit where
condition:
DELETE FROM numtable
Related Topics
How to Dynamically Set Table Name in Eloquent Model
Patterns for PHP Multi Processes
How to Allow a User to Download a File Which Is Stored Outside of the Webroot
How to Run from PHP a Bash Script Under Root User
Restrict Content Access to Logged in Users with PHP
How to Fetch Account Data from a Provider with Lightopenid
Attach Image to Facebook Event (PHP Sdk, Rest or Graph API)
Url Encoded Forward Slashes Breaking My Codeigniter App
Implementing Oauth2 Login, Fatal Error: Class 'Google_Service' Not Found
Wordpress, Nginx Proxy and Subdirectory: Wp-Login.PHP Redirects to Domain
Why Is My Database Backup Script Not Working in PHP
Php's Simplexml: How to Use Colons in Names
HTML PHP Display Username After Success Login