PHP mysqli query not working from php file, but working from command line [closed]

I am trying to query a database from php:

<?php
$conn = new mysqli('localhost', 'root', 'password!', 'db');
$item = $_POST['item'];
$username =$_POST['username'];

$conn->query("DELETE FROM userData WHERE username = '$username' AND listdata = '$item';")

even though the $username and $item match the values in a row in the database, this query fails to delete that row.

If you remove the AND listdata = '$item' portion of the query it does delete rows. Does anyone know why the one part of the query makes it not work? Thanks.