I have this code and would like to delete a list of users when the form was submitted, but it is not working: Any tips?
if (!empty($_POST['username']) && !empty($_POST['email'])) {
$query = mysql_query('INSERT INTO users (name, email, joined) VAlUES ("'.$_POST['username'].'", "' .$_POST['email'].'", NOW())') or die ('daw');
echo ('Cool<br>');
unset($_POST['username']);
unset($_POST['email']);
}
else {
echo ('<strong style="color:red;">FILLLL</strong>');
}
$sql = ('SELECT * FROM users');
$mydata = mysql_query($sql, $con);
function deleteAll() {
mysql_query('DELETE FROM users');
}
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Register</title>
<meta name="viewport" content="width=width-device, initial-scale=1.0"/>
</head>
<body>
<form action ="register.php" method="POST">
Username:
<br>
<input type ="text" name ="username" value=""/>
<br><br>
Email:
<br>
<input type ="text" name ="email" value=""/>
<br><br>
<input type="submit" name ="submit" value="Register!">
</form>
<table>
<?php
while ($result = mysql_fetch_array($mydata)) {
echo ('<tr>
<td>' .ucfirst($result['name']). '</td>
<td>' .$result['email']. '</td>
<td>' .date('F j, Y, H:i ', strtotime($result['joined'])).'</td>
</tr>');
}
?>
</table>
<input type="button" value="deleteAll" class="botao" onclick="deleteAll();" />
</body>
</html>