I'm trying to delete a record from my database... before I get into the specifics here's the code: <? // I have all the correct username and password stuff up here... mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $id = $_POST['id']; echo $id; $query = "DELETE FROM 'apptsubmiss' WHERE 'id' = $id;"; mysql_query($query) or die("Query error"); echo "Successfully deleted."; echo "<form action='displayappts.php'><input type='submit' name='submit' value='Back' /></form>"; ?> PHP: I echoed the $id just to make sure it was there. It was what I wanted, however, there's a query error. Is it because I included a variable in the query or is it because the query itself is just wrong?
Instead of using single quotes around the fields / tables, use back quotes. $query = "DELETE FROM `apptsubmiss` WHERE `id` = '$id'"; PHP:
no quotes for field name is OK but you should give single quotes to the value!! <?php $query = "DELETE FROM apptsubmiss WHERE id = '$id';"; ?> Code (markup):
$query = "DELETE FROM 'apptsubmiss' WHERE 'id' = $id;"; should read $query = "DELETE FROM apptsubmiss WHERE id='$id'"; the semi colon inside the query string is not mandatory but it wouldn't hurt if you keep it.