I can not execute DELETE in SQL when submitting form via POST in PHP

-1

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>
    
asked by anonymous 16.04.2014 / 18:02

1 answer

5

The way your sql query was written is erroneous, the correct syntax is: DELETE FROM TABELA

To call the PHP function of the form you're trying to do, you need to call it a

16.04.2014 / 18:46