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.

3
  • 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 Commented Dec 26, 2020 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" and "How can I prevent SQL injection in PHP?". Commented Dec 26, 2020 at 23:38
  • Records can be deleted with a DELETE statement. Commented Dec 26, 2020 at 23:40

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.