I'm currently just messing around with mysql. I'm not able to delete all the rows from the table "amount" with this code mysqli_query($conn, "DELETE FORM amount");
. With that code, I'm not even able to access my page.
$conn = new mysqli(localhost, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO freetexts (amount)
VALUES ('3')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$sql = "SELECT amount FROM freetexts";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "Amount: " . $row["amount"];
}
} else {
echo "0 results";
}
mysqli_query($conn, "DELETE FROM amount");
$conn->close();
$column = freetexts;
You need to change
mysqli_query($conn, "DELETE FROM amount");
to
mysqli_query($conn, "DELETE FROM `$column` WHERE 1");
Change
mysqli_query($conn, "DELETE FORM amount");
Into
mysqli_query($conn, "DELETE FROM amount");
(misspelled FROM
)
I also think you dont want to delete all records from the table amount
, but just the found record in the table freetexts
... So that would mean you need to alter the query. To give you further advice on something like this, update your question with a table-layout.
The BD probably has a protection denying the command to delete all rows without a condition clause.
Try this: TRUNCATE [table_name]