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>";
}

<?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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.