Jump to content

[SOLVED] Can DELETE queries have WHERE and AND parameters?


RyanSF07

Recommended Posts

Hi Guys

 

I want to be able to DELETE "assignments" from the Scores table WHERE such and such AND something else. Is that possible?

 

Code below --

 

if ($_GET[delete_assignment_id]) {

$sql3 = "DELETE FROM scores WHERE scores.assignment_number = '$_GET[delete_assignment_id]' AND registered_users.id = $_SESSION[user_id]";
if (mysql_query($sql3)) {

	$content .= "<h2>The scores have been deleted</h2>
	<h2><a href='my_account_view_scores.php'>Please click here to see the updated list.</a></h2>";

} else {
	$content .= "<p>The scores could not be deleted due to a system error.</p>";
}

Link to comment
Share on other sites

<?php
if (isset($_GET['delete_assignment_id'])) {
$delete_assignment_id = (int) $_GET['delete_assignment_id'];
$sql3 = "DELETE FROM `scores` 
	WHERE `scores`.`assignment_number` = $delete_assignment_id 
	AND `registered_users`.`id` = $_SESSION['user_id']";
if (mysql_query($sql3)) {
	$content .= "<h2>The scores have been deleted</h2>
	<h2><a href='my_account_view_scores.php'>Please click here to see the updated list.</a></h2>";
} else {
	$content .= "<p>The scores could not be deleted due to a system error.</p>";
}
}

 

That's how you want the code, but the following won't work

 

DELETE FROM `scores`

WHERE `scores`.`assignment_number` = $delete_assignment_id

AND `registered_users`.`id` = $_SESSION['user_id']

 

The `registered_users`.`id` = $_SESSION['user_id'] part is checking a different table;

 

1. why would you want to

2. it can't be done like that

Link to comment
Share on other sites

Thank you -- the problem I see is that different teachers will inevitably call their assignments the same number. John's assignment is #14, but so is Kim's.

 

Thus deleting all assignments numbered "14" will delete other teacher's assignment's scores.

 

So I wonder if there is a was to say only delete the assignment scores for "this" teacher -- as in, registered_users.id = $_SESSION[user_id]

 

Possible?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.