0

I am new to php. I have inserted some multiple checkboxes' values into my database table using implode. Here is the code.

`$checkBox = implode(",", $_POST['car']);

if(isset($_POST['addcar']))
{       
   $username = $_SESSION['username'];
    $query1="INSERT INTO vehicle (username,car) VALUES ('$username', '" . $checkBox . "')   ";     

mysqli_query($db,$query1);



}`

But i can't find how to delete records. Could someone please help me. Thank you for the answers in advance.

Kevin
  • 19
  • 4
  • See about sql injection and the importance of prepared and bound queries, and consider whether a hard delete is really something you want your users to be able to do – Strawberry Dec 26 '20 at 23:36
  • Side note: Do not use string interpolation or concatenation to get values into SQL queries. That's error prone and might make your program vulnerable to SQL injection attacks. Use parameterized queries. See ["How to include a PHP variable inside a MySQL statement"](https://stackoverflow.com/questions/7537377/how-to-include-a-php-variable-inside-a-mysql-statement) and ["How can I prevent SQL injection in PHP?"](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). – sticky bit Dec 26 '20 at 23:38
  • Records can be deleted with a [`DELETE statement`](https://dev.mysql.com/doc/refman/8.0/en/delete.html). – sticky bit Dec 26 '20 at 23:40

1 Answers1

1

First of all, you've to be aware of SQL-injection. Since you are new at PHP, hope that you'll learn that terms. Now I am just going trough your code. Try this:

$checkBox = implode(",", $_POST['car']);

$query1="DELETE FROM table WHERE car IN ($checkBox) ";

mysqli_query($db,$query1);