Clear Data in MySQL Table with PHP

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



Leave a reply



Submit